[FFmpeg-cvslog] vp8: improve memory allocation checks

Vittorio Giovara git at videolan.org
Thu Feb 12 18:11:45 CET 2015


ffmpeg | branch: release/2.5 | Vittorio Giovara <vittorio.giovara at gmail.com> | Wed Dec 17 16:02:08 2014 +0100| [8acbba0ec3b267512842537011172457c57361ba] | committer: Michael Niedermayer

vp8: improve memory allocation checks

Check memory earlier, check one more allocation and clean up on error.

CC: libav-stable at libav.org
Bug-Id: CID 1257773
(cherry picked from commit 014b6b416fec89777cb9cff61bcf7896eaf7cf39)

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavcodec/vp8.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 6ad26f3..5d3123d 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -176,19 +176,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;



More information about the ffmpeg-cvslog mailing list