[FFmpeg-trac] #4899(avcodec:open): memory leak when reencoding to native encoder

FFmpeg trac at avcodec.org
Sat Jan 2 11:18:09 CET 2016


#4899: memory leak when reencoding to native encoder
-------------------------------------+-------------------------------------
             Reporter:  svvitch      |                    Owner:
                 Type:  defect       |                   Status:  open
             Priority:  important    |                Component:  avcodec
              Version:  git-master   |               Resolution:
             Keywords:  leak         |               Blocked By:
  regression                         |  Reproduced by developer:  1
             Blocking:               |
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------

Comment (by rogerdpack):

 Here is a valgrind output (not very helpful I'm afraid [I'm on OS X]):
 https://gist.github.com/rdp/42c8e315cc6438f96249 (the biggest leak is
 reported at the very bottom).

 Also it doesn't matter if input is mpegts or avi, still leaks.
 Also note that with testsrc input there's no leak (possibly because its
 rawvideo).
 A possible offending aspect of the commit may be this:
 {{{
 diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
 index 35c7839..84e9dc8 100644
 --- a/libavcodec/mpegvideo_enc.c
 +++ b/libavcodec/mpegvideo_enc.c
 @@ -1475,8 +1475,7 @@ static void frame_end(MpegEncContext *s)
          }
      }

 -    s->avctx->coded_frame = s->current_picture_ptr->f;
 -
 +    av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
  }

 }}}

 reverting it in my own hackish manner and the leaks at least seem less,
 FWIW.

 {{{
 diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
 index fec4eca..02aec3a 100644
 --- a/libavcodec/mpegvideo_enc.c
 +++ b/libavcodec/mpegvideo_enc.c
 @@ -1617,7 +1617,8 @@ static void frame_end(MpegEncContext *s)
      if (s->pict_type!= AV_PICTURE_TYPE_B)
          s->last_non_b_pict_type = s->pict_type;

 -    av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
 +//    av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
 +    s->avctx->coded_frame = s->current_picture_ptr->f;
  }

  static void update_noise_reduction(MpegEncContext *s)
 diff --git a/libavcodec/utils.c b/libavcodec/utils.c
 index 3aa861a..6c1e88c 100644
 --- a/libavcodec/utils.c
 +++ b/libavcodec/utils.c
 @@ -2909,7 +2909,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
      av_freep(&avctx->priv_data);
      if (av_codec_is_encoder(avctx->codec)) {
          av_freep(&avctx->extradata);
 -        av_frame_free(&avctx->coded_frame);
 +        // disabled for now 4899 av_frame_free(&avctx->coded_frame);
      }
      avctx->codec = NULL;
      avctx->active_thread_type = 0;
 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/4899#comment:13>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list