[FFmpeg-cvslog] avcodec/smacker: Directly goto error in case of error

Andreas Rheinhardt git at videolan.org
Fri Sep 18 03:31:45 EEST 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Sat Jul 25 13:05:06 2020 +0200| [4656c1771b4ac12d9df9812390551f32fda181bc] | committer: Andreas Rheinhardt

avcodec/smacker: Directly goto error in case of error

The earlier version did not error out directly in case an error happens,
because it would lead to a leak: An allocated array is only reachable
via a local variable at that time; it is only attached to more permanent
storage at the end. While it would be possible to add custom code for
freeing on error (instead of reusing the ordinary code for doing so),
this commit takes the opposite approach and attaches the newly allocated
array to its permanent place immediately after its allocation.

Reviewed-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

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

 libavcodec/smacker.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 8a4d88cfed..4b1f0f1b7c 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -251,17 +251,18 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int
         err = AVERROR(ENOMEM);
         goto error;
     }
+    *recodes = huff.values;
 
     res = smacker_decode_bigtree(gb, &huff, &ctx, 0);
-    if (res < 0)
+    if (res < 0) {
         err = res;
+        goto error;
+    }
     skip_bits1(gb);
     if(ctx.last[0] == -1) ctx.last[0] = huff.current++;
     if(ctx.last[1] == -1) ctx.last[1] = huff.current++;
     if(ctx.last[2] == -1) ctx.last[2] = huff.current++;
 
-    *recodes = huff.values;
-
 error:
     for (int i = 0; i < 2; i++) {
         if (vlc[i].table)



More information about the ffmpeg-cvslog mailing list