diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-04-11 13:37:24 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-04-18 00:22:22 +0200 |
commit | a43120b609db300a4b3fa086d6ac753c13e6bf6d (patch) | |
tree | 1d8d2656f972e0966cf6bfb20ef62a9d1876129f /libavformat/mux.c | |
parent | 1004a92cd44404ad55a75509cd289a70fa03d333 (diff) |
avformat/mux: Fix leak when adding packet to interleavement queue fails
When an error happened in ff_interleave_add_packet() when adding
a packet to the packet queue, said packet would not be unreferenced
in ff_interleave_add_packet(), but would be zeroed in
av_interleaved_write_frame(), which results in a memleak.
This has been fixed: ff_interleave_add_packet() now always unreferences
the input packet on error; as a result, it always returns blank packets
which has been documented. Relying on this a call to av_packet_unref()
in ff_audio_rechunk_interleave() can be removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/mux.c')
-rw-r--r-- | libavformat/mux.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c index 67326292be..92e5636dbe 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -917,10 +917,13 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int chunked = s->max_chunk_size || s->max_chunk_duration; this_pktl = av_malloc(sizeof(AVPacketList)); - if (!this_pktl) + if (!this_pktl) { + av_packet_unref(pkt); return AVERROR(ENOMEM); + } if ((ret = av_packet_make_refcounted(pkt)) < 0) { av_free(this_pktl); + av_packet_unref(pkt); return ret; } @@ -1215,7 +1218,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) av_init_packet(pkt); pkt = NULL; } - if (ret <= 0) //FIXME cleanup needed for ret<0 ? + if (ret <= 0) return ret; ret = write_packet(s, &opkt); |