hozuki / MonoGame.Extended2

A collection of extensions for MonoGame
BSD 3-Clause Clear License
38 stars 8 forks source link

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

Open SebDaMuffin opened 7 months ago

SebDaMuffin commented 7 months ago

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()

https://github.com/hozuki/MonoGame.Extended2/blob/a20100b0a2e2dbd0480477e8aaab903cb52db9b2/Sources/MonoGame.Extended.VideoPlayback/DecodeContext.cs#L35-L37

Dispose()

https://github.com/hozuki/MonoGame.Extended2/blob/a20100b0a2e2dbd0480477e8aaab903cb52db9b2/Sources/MonoGame.Extended.VideoPlayback/DecodeContext.cs#L697-L701

avformat_alloc_context()

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