Opened 4 years ago

Last modified 8 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



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 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 (3)

comment:1 Changed 4 years ago by cehoyos

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

comment:2 Changed 4 years ago by nguydavi

An simple example is the exact code from this example, just changing line 91 to

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

comment:3 Changed 8 months ago by Balling

Is this still not fixed?

Note: See TracTickets for help on using tickets.