[FFmpeg-devel] [PATCH 2/2] lavc/options: fix leaks in avcodec_copy_context

Lukasz Marek lukasz.m.luki2 at gmail.com
Tue Dec 2 19:29:35 CET 2014


On 27 November 2014 at 17:56, Lukasz Marek <lukasz.m.luki2 at gmail.com> wrote:

> On 27 November 2014 at 04:17, Michael Niedermayer <michaelni at gmx.at>
> wrote:
>
>> On Thu, Nov 27, 2014 at 12:43:57AM +0100, Lukasz Marek wrote:
>> > On 24.11.2014 05:16, Lukasz Marek wrote:
>> > >Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
>> > >---
>> > >  libavcodec/options.c | 23 +++++++++++------------
>> > >  1 file changed, 11 insertions(+), 12 deletions(-)
>> > >
>> > >diff --git a/libavcodec/options.c b/libavcodec/options.c
>> > >index 7f9fb07..8ba997c 100644
>> > >--- a/libavcodec/options.c
>> > >+++ b/libavcodec/options.c
>> > >@@ -190,6 +190,11 @@ int avcodec_copy_context(AVCodecContext *dest,
>> const AVCodecContext *src)
>> > >      }
>> > >
>> > >      av_opt_free(dest);
>> > >+    av_freep(&dest->rc_override);
>> > >+    av_freep(&dest->intra_matrix);
>> > >+    av_freep(&dest->inter_matrix);
>> > >+    av_freep(&dest->extradata);
>> > >+    av_freep(&dest->subtitle_header);
>> > >
>> > >      memcpy(dest, src, sizeof(*dest));
>> > >      av_opt_copy(dest, src);
>> > >@@ -205,13 +210,7 @@ int avcodec_copy_context(AVCodecContext *dest,
>> const AVCodecContext *src)
>> > >      dest->slice_offset    = NULL;
>> > >      dest->hwaccel         = NULL;
>> > >      dest->internal        = NULL;
>> > >-
>> > >-    /* reallocate values that should be allocated separately */
>> > >-    dest->extradata       = NULL;
>> > >-    dest->intra_matrix    = NULL;
>> > >-    dest->inter_matrix    = NULL;
>> > >-    dest->rc_override     = NULL;
>> > >-    dest->subtitle_header = NULL;
>> >
>> >
>> > This should stay. Updated version attched
>> >
>>
>> >  options.c |   16 +++++++++++-----
>> >  1 file changed, 11 insertions(+), 5 deletions(-)
>> > 971d1769e50d2e853d7359003f8c924092a96e6b
>> 0001-lavc-options-fix-leaks-in-avcodec_copy_context.patch
>> > From 722d7e837093212d6e6e6b17814ed408300d25a6 Mon Sep 17 00:00:00 2001
>> > From: Lukasz Marek <lukasz.m.luki2 at gmail.com>
>> > Date: Thu, 27 Nov 2014 00:41:16 +0100
>> > Subject: [PATCH] lavc/options: fix leaks in avcodec_copy_context
>> >
>> > Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
>> > ---
>> >  libavcodec/options.c | 16 +++++++++++-----
>> >  1 file changed, 11 insertions(+), 5 deletions(-)
>>
>> breaks "make fate-lavf-yuv4mpeg"
>>
>> --- ./tests/ref/lavf/yuv4mpeg   2014-11-26 20:04:48.466295490 +0100
>> +++ tests/data/fate/lavf-yuv4mpeg       2014-11-27 04:16:07.234916526
>> +0100
>> @@ -1,2 +0,0 @@
>> -ec8178cb152f9cdbfd9cb724d977db2e *./tests/data/lavf/lavf.y4m
>> -3801808 ./tests/data/lavf/lavf.y4m
>> Test lavf-yuv4mpeg failed. Look at tests/data/fate/lavf-yuv4mpeg.err for
>> details.
>> make: *** [fate-lavf-yuv4mpeg] Error 139
>>
>
> This is because ffmpeg copy opened codec context and assumes copy is also
> opened, but this is against docs:
>
> Copy the settings of the source AVCodecContext into the destination
> AVCodecContext. The resulting destination codec context will be
> unopened, i.e. you are required to call avcodec_open2() before you
> can use this AVCodecContext to decode/encode video/audio data.
>
> I will push a patch for ffmpeg later and this patch have to be cleary
> postponed until ffmpeg is fixed.
>

I have sent patch for ffmpeg. It is not failing after that change.


More information about the ffmpeg-devel mailing list