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

Rostislav Pehlivanov atomnuker at gmail.com
Tue Feb 6 13:16:35 EET 2018


On 6 February 2018 at 06:56, Josh Allmann <joshua.allmann at gmail.com> wrote:

> 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
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

No, its not up to the encoder to free up the extradata. Its up to the API
user to close the avctx for the encoder which will free the extradata, even
if encoder init fails. Besides, if you don't, you'll have a dirty context
from the previous encoder since they don't have to set the same avctx
fields.


More information about the ffmpeg-devel mailing list