]> git.sesse.net Git - ffmpeg/commitdiff
vp8: improve memory allocation checks
authorVittorio Giovara <vittorio.giovara@gmail.com>
Wed, 17 Dec 2014 15:02:08 +0000 (16:02 +0100)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Thu, 15 Jan 2015 00:25:07 +0000 (01:25 +0100)
Check memory earlier, check one more allocation and clean up on error.

CC: libav-stable@libav.org
Bug-Id: CID 1257773

libavcodec/vp8.c

index 9a12346f98e227d524922527bd19ef96e138bffe..4ea6d562b3ec6e990cbca917b60797c103a94434 100644 (file)
@@ -168,19 +168,25 @@ int update_dimensions(VP8Context *s, int width, int height, int is_vp7)
     s->top_border  = av_mallocz((s->mb_width + 1) * sizeof(*s->top_border));
     s->thread_data = av_mallocz(MAX_THREADS * sizeof(VP8ThreadData));
 
+    if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
+        !s->thread_data || (!s->intra4x4_pred_mode_top && !s->mb_layout)) {
+        free_buffers(s);
+        return AVERROR(ENOMEM);
+    }
+
     for (i = 0; i < MAX_THREADS; i++) {
         s->thread_data[i].filter_strength =
             av_mallocz(s->mb_width * sizeof(*s->thread_data[0].filter_strength));
+        if (!s->thread_data[i].filter_strength) {
+            free_buffers(s);
+            return AVERROR(ENOMEM);
+        }
 #if HAVE_THREADS
         pthread_mutex_init(&s->thread_data[i].lock, NULL);
         pthread_cond_init(&s->thread_data[i].cond, NULL);
 #endif
     }
 
-    if (!s->macroblocks_base || !s->top_nnz || !s->top_border ||
-        (!s->intra4x4_pred_mode_top && !s->mb_layout))
-        return AVERROR(ENOMEM);
-
     s->macroblocks = s->macroblocks_base + 1;
 
     return 0;