Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecodeContext constructor tries to free the same context twice when it encounters an error #9

Open
SebDaMuffin opened this issue Jan 25, 2024 · 0 comments

Comments

@SebDaMuffin
Copy link

If ffmpeg.avformat_alloc_context() encounters an error, ffmpeg frees the context. The next line then assigns the freed context to _formatContext. Then ffmpeg.avformat_open_input() returns an error, calling Dispose(), which then tries to free the already freed context, resulting in a crash. Delaying the _formatContext assignment until after FFMpegHelper.Verify() fixes this because Dispose() will not try to free _formatContext.

DecodeContext()

var formatContext = ffmpeg.avformat_alloc_context();
_formatContext = formatContext;
FFmpegHelper.Verify(ffmpeg.avformat_open_input(&formatContext, url, null, null), Dispose);

Dispose()

if (_formatContext != null)
{
ffmpeg.avformat_free_context(_formatContext);
_formatContext = null;
}

avformat_alloc_context()

https://github.com/FFmpeg/FFmpeg/blob/00b288da73f45acb78b74bcc40f73c7ba1fff7cb/libavformat/options.c#L187-L192

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

No branches or pull requests

1 participant