mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:53:50 +00:00
Don't leak the IO context if avformat_open_input fails
This commit is contained in:
parent
63e86555b6
commit
c869444dcf
1 changed files with 7 additions and 7 deletions
|
@ -854,20 +854,20 @@ void VideoState::init(const std::string& resourceName)
|
|||
if(this->stream.isNull())
|
||||
throw std::runtime_error("Failed to open video resource");
|
||||
|
||||
AVIOContext *ioCtx = avio_alloc_context(NULL, 0, 0, this, OgreResource_Read, OgreResource_Write, OgreResource_Seek);
|
||||
if(!ioCtx) throw std::runtime_error("Failed to allocate AVIOContext");
|
||||
|
||||
this->format_ctx = avformat_alloc_context();
|
||||
this->format_ctx->pb = avio_alloc_context(NULL, 0, 0, this, OgreResource_Read, OgreResource_Write, OgreResource_Seek);
|
||||
if(!this->format_ctx->pb)
|
||||
{
|
||||
avformat_free_context(this->format_ctx);
|
||||
throw std::runtime_error("Failed to allocate ioContext ");
|
||||
}
|
||||
if(this->format_ctx)
|
||||
this->format_ctx->pb = ioCtx;
|
||||
|
||||
// Open video file
|
||||
/// \todo leak here, ffmpeg or valgrind bug ?
|
||||
if (avformat_open_input(&this->format_ctx, resourceName.c_str(), NULL, NULL))
|
||||
if(!this->format_ctx || avformat_open_input(&this->format_ctx, resourceName.c_str(), NULL, NULL))
|
||||
{
|
||||
// "Note that a user-supplied AVFormatContext will be freed on failure."
|
||||
this->format_ctx = NULL;
|
||||
av_free(ioCtx);
|
||||
throw std::runtime_error("Failed to open video input");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue