Opened 8 years ago

Closed 3 years ago

#5714 closed defect (duplicate)

Memory leak using AVStream

Reported by: David Nguyen 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 (4)

comment:1 by Carl Eugen Hoyos, 8 years ago

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

comment:2 by David Nguyen, 8 years ago

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);

comment:3 by Balling, 4 years ago

Is this still not fixed?

comment:4 by mkver, 3 years ago

Resolution: duplicate
Status: newclosed

Should have been fixed in b9d2005ea5d6837917a69bc2b8e98f5695f54e39. Also, this is a duplicate of #2716.

Note: See TracTickets for help on using tickets.