[FFmpeg-cvslog] avcodec/encode: do proper cleanup on failure

James Almer git at videolan.org
Tue Oct 3 20:04:07 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Oct  3 11:49:18 2017 -0300| [87e625c2633a83f62f155fcca33dab0a6e2bb5e6] | committer: James Almer

avcodec/encode: do proper cleanup on failure

Fixes the last remaining memleaks introduced by a22c6a4796ca1f2cbee6784262515da876fbec22.

Signed-off-by: James Almer <jamrial at gmail.com>

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

 libavcodec/encode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index c152228c92..c961dbace1 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -225,9 +225,9 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
         } else if (!avpkt->buf) {
             AVPacket tmp = { 0 };
             ret = av_packet_ref(&tmp, avpkt);
-            if (ret < 0)
-                return ret;
             av_packet_unref(avpkt);
+            if (ret < 0)
+                goto end;
             *avpkt = tmp;
         }
     }
@@ -324,9 +324,9 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
         } else if (!avpkt->buf) {
             AVPacket tmp = { 0 };
             ret = av_packet_ref(&tmp, avpkt);
+            av_packet_unref(avpkt);
             if (ret < 0)
                 return ret;
-            av_packet_unref(avpkt);
             *avpkt = tmp;
         }
     }



More information about the ffmpeg-cvslog mailing list