[FFmpeg-trac] #2216(avcodec:new): memory leak in calling avcodec_alloc_context3 and then avcodec_copy_context

FFmpeg trac at avcodec.org
Thu Jan 31 11:19:20 CET 2013


#2216: memory leak in calling avcodec_alloc_context3 and then avcodec_copy_context
-------------------------------------+----------------------------------
             Reporter:  vinxxe       |                     Type:  defect
               Status:  new          |                 Priority:  minor
            Component:  avcodec      |                  Version:  1.1.1
             Keywords:  memory leak  |               Blocked By:
             Blocking:               |  Reproduced by developer:  1
Analyzed by developer:  1            |
-------------------------------------+----------------------------------
 Summary of the bug:

 in the documentation of the '''avcodec_copy_context''' function is clearly
 stated that the '''dest''' target codec context should be initialized with
 '''avcodec_alloc_context3'''.
 If you perform this pair of calls, one after the other, the
 '''avcodec_alloc_context3''' will allocate some memory pointed by the
 '''priv_data''' field of the codec context (file
 '''libavcodec/options.c''', line '''128''') through the call of the
 '''avcodec_get_context_defaults3''' function, but the following call to
 the '''avcodec_copy_context''' (with '''dest''' parameter set to the newly
 allocated codec context) will overwrite the '''priv_data''' pointer
 without deallocating the memory reserved by the
 '''avcodec_get_context_defaults3''', so causing a memory leak.

 How to reproduce:
 {{{

    AVCodec  *codec;
    AVCodecContext    *SourceCodecCtx, *DestCodecCtx;

    ...

    DestCodecCtx = avcodec_alloc_context3(codec);
    avcodec_copy_context(DestCodecCtx, SourceCodecCtx);


 }}}

-- 
Ticket URL: <https://ffmpeg.org/trac/ffmpeg/ticket/2216>
FFmpeg <http://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list