[FFmpeg-cvslog] truemotion2: Check memory allocation

Vittorio Giovara git at videolan.org
Mon Jun 1 02:54:42 CEST 2015


ffmpeg | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Sun May 31 14:55:27 2015 +0200| [e1ea365f7e1477c78865b866a180712174536c20] | committer: Luca Barbato

truemotion2: Check memory allocation

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

 libavcodec/truemotion2.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index 122643d..094096e 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -171,6 +171,10 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
     huff.nums    = av_mallocz(huff.max_num * sizeof(int));
     huff.bits    = av_mallocz(huff.max_num * sizeof(uint32_t));
     huff.lens    = av_mallocz(huff.max_num * sizeof(int));
+    if (!huff.nums || !huff.bits || !huff.lens) {
+        res = AVERROR(ENOMEM);
+        goto out;
+    }
 
     res = tm2_read_tree(ctx, 0, 0, &huff);
 
@@ -193,10 +197,16 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
             code->bits = huff.max_bits;
             code->length = huff.max_num;
             code->recode = av_malloc(code->length * sizeof(int));
+            if (!code->recode) {
+                res = AVERROR(ENOMEM);
+                goto out;
+            }
             for (i = 0; i < code->length; i++)
                 code->recode[i] = huff.nums[i];
         }
     }
+
+out:
     /* free allocated memory */
     av_free(huff.nums);
     av_free(huff.bits);



More information about the ffmpeg-cvslog mailing list