[FFmpeg-devel] [PATCH v4 2/9] avformat/utils: unref packet on AVInputFormat.read_packet() failure
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Fri Sep 20 23:39:09 EEST 2019
From: James Almer <jamrial at gmail.com>
Demuxers may have allocated a packet before encountering an error and aborting.
Fixes ticket #8150
Signed-off-by: James Almer <jamrial at gmail.com>
---
Earlier versions of this patchset used av_init_packet() together with
setting the size and data to zero/NULL. This would have caused memleaks
when the packet contained data that needs to be freed/unreferenced,
whereas this approach here runs the risk of double freeing. I consider
the risk of the latter much lower than the risk of the former and have
therefore included this patch in this patchset.
libavformat/utils.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 652642a71b..e348df3269 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -854,6 +854,8 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
av_init_packet(pkt);
ret = s->iformat->read_packet(s, pkt);
if (ret < 0) {
+ av_packet_unref(pkt);
+
/* Some demuxers return FFERROR_REDO when they consume
data and discard it (ignored streams, junk, extradata).
We must re-call the demuxer to get the real packet. */
--
2.20.1
More information about the ffmpeg-devel
mailing list