summaryrefslogtreecommitdiff
path: root/libavformat/mux.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-04-11 11:45:32 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-04-18 00:14:05 +0200
commit1004a92cd44404ad55a75509cd289a70fa03d333 (patch)
treec768e95e7885ff765efb1873d0b595684d92bbd2 /libavformat/mux.c
parentad1dc918a010d9d75e8babbe42a3996e1af00cb0 (diff)
avformat/mux: Fix leaks on error when writing noninterleaved uncoded frames
If writing uncoded frames in noninterleaved mode fails at the preparatory steps (i.e. before it reaches write_packet()), the packet would not be unreferenced and the frame would leak. This is fixed by unreferencing the packet in write_uncoded_frame_internal() instead. This also makes it possible to remove the unreferencing in write_packet() itself: In noninterleaved mode frames are now freed in write_uncoded_frame_internal(), while they are freed in interleaved mode when their containing packet gets unreferenced (like normal packets). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/mux.c')
-rw-r--r--libavformat/mux.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c
index bb54fd5528..67326292be 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -743,7 +743,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
AVFrame **frame = (AVFrame **)pkt->data;
av_assert0(pkt->size == sizeof(*frame));
ret = s->oformat->write_uncoded_frame(s, pkt->stream_index, frame, 0);
- av_packet_unref(pkt);
} else {
ret = s->oformat->write_packet(s, pkt);
}
@@ -1318,6 +1317,7 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
AVFrame *frame, int interleaved)
{
AVPacket pkt, *pktp;
+ int ret;
av_assert0(s->oformat);
if (!s->oformat->write_uncoded_frame) {
@@ -1354,8 +1354,11 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
pkt.flags |= AV_PKT_FLAG_UNCODED_FRAME;
}
- return interleaved ? av_interleaved_write_frame(s, pktp) :
- av_write_frame(s, pktp);
+ ret = interleaved ? av_interleaved_write_frame(s, pktp) :
+ av_write_frame(s, pktp);
+ if (pktp)
+ av_packet_unref(pktp);
+ return ret;
}
int av_write_uncoded_frame(AVFormatContext *s, int stream_index,