[Ffmpeg-devel] Re: Memory leaks with some codecs... (again)

Burkhard Plaum plaum
Fri Feb 3 19:00:05 CET 2006


Hi,

> ==3114== 1560 bytes in 2 blocks are definitely lost in loss record 1 of 2
> ==3114==    at 0x1B905141: memalign (vg_replace_malloc.c:216)
> ==3114==    by 0x80ABB8E: av_malloc (mem.c:62)
> ==3114==    by 0x80AB364: avcodec_alloc_context (utils.c:803)
> ==3114==    by 0x80597C1: av_new_stream (utils.c:2194)
> ==3114==    by 0x8054B0C: add_video_stream (output_example.c:187)
> ==3114==    by 0x805490E: main (output_example.c:447)

That's NO candidate for av_mallocz_static. Instead, the codec context must
be freed when no longer used (i.e. before the corresponding AVStream is 
freed).

> ==3114== 65552 bytes in 2 blocks are still reachable in loss record 2 of 2
> ==3114==    at 0x1B905141: memalign (vg_replace_malloc.c:216)
> ==3114==    by 0x80ABB8E: av_malloc (mem.c:62)
> ==3114==    by 0x80A9E26: av_mallocz (utils.c:63)
> ==3114==    by 0x80B7BFB: MPV_encode_defaults (mpegvideo.c:596)
> ==3114==    by 0x80AD959: MPV_encode_init (mpegvideo.c:894)
> ==3114==    by 0x80AA643: avcodec_open (utils.c:867)
> ==3114==    by 0x8054C70: open_video (output_example.c:262)
> ==3114==    by 0x80544F1: main (output_example.c:465)

That's a global variable (default_mv_penalty), which should be
allocated with av_mallocz_static.

The rule for leaks is:

- If valgrind reports "still reachable", AND the pointer is in global
  scope, av_mallocz_static is the solution.

- In all other cases, av_mallocz_static is terribly wrong. Instead,
  the memory must be freed by the right *_close() (or whatever) 
  function.

Hope this helps

Burkhard





More information about the ffmpeg-devel mailing list