diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 737cd0d1c8f5bba48bcbee2b63d1768973382a1d..af6dd611e508053d98bbc45393536f191d45c754 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -981,7 +981,8 @@ alloc:
         if(s->current_picture_ptr)
             pic->coded_picture_number= s->current_picture_ptr->coded_picture_number+1;
         
-        alloc_picture(s, (Picture*)pic, 0);
+        if( alloc_picture(s, (Picture*)pic, 0) < 0)
+            return -1;
 
         s->current_picture_ptr= &s->picture[i];
     }