[FFmpeg-devel] [PATCH] aacenc: Free any extradata before re-allocating.

Josh Allmann joshua.allmann at gmail.com
Tue Feb 6 08:56:35 EET 2018


Fixes a leak that occurs if avctx->extradata contains any data
prior to opening the codec, eg left over from an initialization
call to avcodec_parameters_from_context.
---
 libavcodec/aacenc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 6d94c76905..f8fbe69d87 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -98,6 +98,10 @@ static int put_audio_specific_config(AVCodecContext *avctx)
     int channels = (!s->needs_pce)*(s->channels - (s->channels == 8 ? 1 : 0));
     const int max_size = 32;
 
+    if (avctx->extradata) {
+        av_freep(&avctx->extradata);
+        avctx->extradata_size = 0;
+    }
     avctx->extradata = av_mallocz(max_size);
     if (!avctx->extradata)
         return AVERROR(ENOMEM);
-- 
2.14.2



More information about the ffmpeg-devel mailing list