[FFmpeg-cvslog] avcodec_encode_{audio, video}: only reallocate output packet when it has non-zero size.

Anton Khirnov git at videolan.org
Thu Mar 29 04:32:33 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Mar 27 08:21:02 2012 +0200| [3c6607eb6f946ed3e108db3f0694cab7e5a5df7e] | committer: Anton Khirnov

avcodec_encode_{audio,video}: only reallocate output packet when it has non-zero size.

Otherwise realloc would free it, which would result in double free
later.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c6607eb6f946ed3e108db3f0694cab7e5a5df7e
---

 libavcodec/utils.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 7d50bd5..aa0f5b6 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -960,7 +960,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
             avctx->frame_size = fs_tmp;
     }
     if (!ret) {
-        if (!user_packet && avpkt->data) {
+        if (!user_packet && avpkt->size) {
             uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
             if (new_data)
                 avpkt->data = new_data;
@@ -1123,7 +1123,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
         else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
             avpkt->pts = avpkt->dts = frame->pts;
 
-        if (!user_packet && avpkt->data) {
+        if (!user_packet && avpkt->size) {
             uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
             if (new_data)
                 avpkt->data = new_data;



More information about the ffmpeg-cvslog mailing list