1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-10 16:14:26 +00:00

Fix crash when avformat_open_input fails (Fixes #1522)

This commit is contained in:
scrawl 2014-06-17 21:16:32 +02:00
parent d4678a8d55
commit 80f66e2157

View File

@ -159,17 +159,21 @@ void FFmpeg_Decoder::open(const std::string &fname)
mFormatCtx->pb = avio_alloc_context(NULL, 0, 0, this, readPacket, writePacket, seek); mFormatCtx->pb = avio_alloc_context(NULL, 0, 0, this, readPacket, writePacket, seek);
if(!mFormatCtx->pb || avformat_open_input(&mFormatCtx, fname.c_str(), NULL, NULL) != 0) if(!mFormatCtx->pb || avformat_open_input(&mFormatCtx, fname.c_str(), NULL, NULL) != 0)
{ {
if (mFormatCtx->pb != NULL) // "Note that a user-supplied AVFormatContext will be freed on failure".
if (mFormatCtx)
{ {
if (mFormatCtx->pb->buffer != NULL) if (mFormatCtx->pb != NULL)
{ {
av_free(mFormatCtx->pb->buffer); if (mFormatCtx->pb->buffer != NULL)
mFormatCtx->pb->buffer = NULL; {
} av_free(mFormatCtx->pb->buffer);
av_free(mFormatCtx->pb); mFormatCtx->pb->buffer = NULL;
mFormatCtx->pb = NULL; }
av_free(mFormatCtx->pb);
mFormatCtx->pb = NULL;
}
avformat_free_context(mFormatCtx);
} }
avformat_free_context(mFormatCtx);
mFormatCtx = NULL; mFormatCtx = NULL;
fail("Failed to allocate input stream"); fail("Failed to allocate input stream");
} }