Skip to content

fix(runtime): free custom AVIO buffers on all exits - #3449

Open
wangxiuwen wants to merge 1 commit into
modelscope:mainfrom
wangxiuwen:fix/ffmpeg-avio-buffer-lifetime
Open

fix(runtime): free custom AVIO buffers on all exits#3449
wangxiuwen wants to merge 1 commit into
modelscope:mainfrom
wangxiuwen:fix/ffmpeg-avio-buffer-lifetime

Conversation

@wangxiuwen

Copy link
Copy Markdown

What does this PR do?

Free the buffer owned by the custom AVIOContext on every exit from the in-memory FFmpeg loader.

The cleanup helper follows FFmpeg's custom-I/O example: close the format input first, free the context's current buffer, and then call avio_context_free. It deliberately reads avio_ctx->buffer at cleanup time because libavformat may replace the original buffer while probing.

Reference: https://ffmpeg.org/doxygen/trunk/avio_read_callback_8c-example.html

Why is this needed?

The error paths previously called only avio_context_free, which does not release the caller-supplied/current AVIO buffer. Every failed in-memory decode therefore leaked the copied input buffer. The success path also freed the context structure directly instead of using the public FFmpeg cleanup API.

Validation

  • git diff --check
  • Audited all seven error exits and the success exit in Audio::FfmpegLoad(const char*, int).
  • Verified format cleanup precedes custom AVIO cleanup, matching the FFmpeg example.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant