From 6107d5bad26188ba772a998639b17aeadd6dfd28 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Mon, 30 Dec 2013 22:16:06 +0100 Subject: [PATCH] Updated ffmpeg decoder fix Signed-off-by: Lukasz Gromanowski --- apps/openmw/mwsound/ffmpeg_decoder.cpp | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwsound/ffmpeg_decoder.cpp b/apps/openmw/mwsound/ffmpeg_decoder.cpp index b5a2ff1d1..13d11f691 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.cpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.cpp @@ -160,7 +160,12 @@ void FFmpeg_Decoder::open(const std::string &fname) { 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; } avformat_free_context(mFormatCtx); @@ -200,7 +205,12 @@ void FFmpeg_Decoder::open(const std::string &fname) } 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; avformat_close_input(&mFormatCtx); @@ -221,16 +231,16 @@ void FFmpeg_Decoder::close() { 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 - // near mFormatCtx->pb - // - // to be checked! - // - // avio_close(mFormatCtx->pb); + // As scrawl pointed, memleak could be related to this ffmpeg ticket: + // https://trac.ffmpeg.org/ticket/1357 // + if (mFormatCtx->pb->buffer != NULL) + { + av_free(mFormatCtx->pb->buffer); + mFormatCtx->pb->buffer = NULL; + } av_free(mFormatCtx->pb); mFormatCtx->pb = NULL; }