Updated ffmpeg decoder fix

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
This commit is contained in:
Lukasz Gromanowski 2013-12-30 22:16:06 +01:00
parent 5c5f87445b
commit 6107d5bad2

View file

@ -160,7 +160,12 @@ void FFmpeg_Decoder::open(const std::string &fname)
{ {
if (mFormatCtx->pb != NULL) if (mFormatCtx->pb != NULL)
{ {
avio_close(mFormatCtx->pb); if (mFormatCtx->pb->buffer != NULL)
{
av_free(mFormatCtx->pb->buffer);
mFormatCtx->pb->buffer = NULL;
}
av_free(mFormatCtx->pb);
mFormatCtx->pb = NULL; mFormatCtx->pb = NULL;
} }
avformat_free_context(mFormatCtx); avformat_free_context(mFormatCtx);
@ -200,7 +205,12 @@ void FFmpeg_Decoder::open(const std::string &fname)
} }
catch(std::exception &e) catch(std::exception &e)
{ {
avio_close(mFormatCtx->pb); if (mFormatCtx->pb->buffer != NULL)
{
av_free(mFormatCtx->pb->buffer);
mFormatCtx->pb->buffer = NULL;
}
av_free(mFormatCtx->pb);
mFormatCtx->pb = NULL; mFormatCtx->pb = NULL;
avformat_close_input(&mFormatCtx); avformat_close_input(&mFormatCtx);
@ -221,16 +231,16 @@ void FFmpeg_Decoder::close()
{ {
if (mFormatCtx->pb != NULL) if (mFormatCtx->pb != NULL)
{ {
avio_flush(mFormatCtx->pb); // valgrind shows memleak near mFormatCtx->pb
// //
// avio-close() gives segfault, but with av_free valgrind shows memleak // As scrawl pointed, memleak could be related to this ffmpeg ticket:
// near mFormatCtx->pb // https://trac.ffmpeg.org/ticket/1357
//
// to be checked!
//
// avio_close(mFormatCtx->pb);
// //
if (mFormatCtx->pb->buffer != NULL)
{
av_free(mFormatCtx->pb->buffer);
mFormatCtx->pb->buffer = NULL;
}
av_free(mFormatCtx->pb); av_free(mFormatCtx->pb);
mFormatCtx->pb = NULL; mFormatCtx->pb = NULL;
} }