[FFmpeg-cvslog] avcodec/encode: unref the packet on AVCodec.receive_packet() failure
James Almer
git at videolan.org
Tue Sep 1 16:06:06 EEST 2020
ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Aug 30 23:57:23 2020 -0300| [0271098e6c9ff8f2a97d65087e424f6d547e53f9] | committer: James Almer
avcodec/encode: unref the packet on AVCodec.receive_packet() failure
Fixes memleaks with some encoders that don't unref the packet before
returning.
This is consistent with the behavior of AVCodec.encode()
implementations in encode_simple_internal().
Found-by: mkver
Reviewed-by: Anton Khirnov <anton at khirnov.net>
Signed-off-by: James Almer <jamrial at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0271098e6c9ff8f2a97d65087e424f6d547e53f9
---
libavcodec/encode.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 8bc10c4abb..2e540baf37 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -242,7 +242,9 @@ static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt
if (avctx->codec->receive_packet) {
ret = avctx->codec->receive_packet(avctx, avpkt);
- if (!ret)
+ if (ret < 0)
+ av_packet_unref(avpkt);
+ else
// Encoders must always return ref-counted buffers.
// Side-data only packets have no data and can be not ref-counted.
av_assert0(!avpkt->data || avpkt->buf);
More information about the ffmpeg-cvslog
mailing list