[FFmpeg-devel] [PATCH] lavformat/utils: Fix a memleak that st->codec->hw_frames_ctx

Hendrik Leppkes h.leppkes at gmail.com
Fri Jan 20 11:48:17 EET 2017


On Fri, Jan 20, 2017 at 8:35 PM, Chao Liu <chaox.a.liu at gmail.com> wrote:
> Have you ever used valgrind? Please just run the command below:
> valgrind --leak-check=full --log-file=out.log ffmpeg -hwaccel qsv
> -qsv_device /dev/dri/renderD128 -c:v h264_qsv -i a.h264 -c:v h264_qsv -b:v
> 2M  -y out.h264
>
> See line 3323 of ffmpeg.c,
>         ret = avcodec_copy_context(ost->st->codec, ost->enc_ctx);
> and see what have been done in avcodec_copy_context:
>     if (src->hw_frames_ctx) {
>         dest->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);
>         if (!dest->hw_frames_ctx)
>             goto fail;
>     }
> However, that is not freed when calling avformat_free_context.
>

avcodec_copy_context is deprecated and should generally not be used
anymore. It would be more appropriate to resolve whatever issue
remains in ffmpeg that it needs to call it.
Otherwise, hw_frames_ctx is supplied by the caller to libavcodec, so
it also should manage its lifetime, I would think, and not be blindly
free'ed by avcodec.

PS:
Please don't top post.

- Hendrik


More information about the ffmpeg-devel mailing list