Opened 17 months ago

Last modified 17 months ago

#5714 new defect

Memory leak using AVStream

Reported by: nguydavi Owned by:
Priority: important Component: avformat
Version: git-master Keywords: leak
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hi,

I am upgrading from FFmpeg 2.8.4 to 3.1.1, and changing code to not use
AVStream.codec anymore. By doing so, I get a memory leak with valgrind,
here's the trace

==15481== at 0x4A07306: memalign (vg_replace_malloc.c:532)
==15481== by 0x4A0735F: posix_memalign (vg_replace_malloc.c:660)
==15481== by 0x6EA3E48: av_malloc (mem.c:97)
==15481== by 0x6EA4165: av_mallocz (mem.c:254)
==15481== by 0x599D3E8: init_context_defaults (options.c:127)
==15481== by 0x599D540: avcodec_alloc_context3 (options.c:163)
==15481== by 0x6BDED26: avformat_new_stream (utils.c:4098)

Seems like AVCodecContext.priv_data is not being freed.

Looking at the code, the AVStream.codec is still being allocated by you and
freed here
https://www.ffmpeg.org/doxygen/3.1/libavformat_2utils_8c_source.html at
line 3980.

I tested adding avcodec_close(st->codec) before av_freep(&st->codec) and the leak is gone.
I used to close st->codec myself before this deprecation.

Did I misused the new AVStream and forgot to call a new method that should free that ?

Change History (2)

comment:1 Changed 17 months ago by cehoyos

Please provide the source code that allows to reproduce the leak.

comment:2 Changed 17 months ago by nguydavi

An simple example is the exact code from this example, https://www.ffmpeg.org/doxygen/3.1/muxing_8c-example.html just changing line 91 to

ost->st = avformat_new_stream(oc, *codec);

Note: See TracTickets for help on using tickets.