]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Return an error when realloc fails.
authorbenoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Tue, 25 Mar 2008 14:48:18 +0000 (14:48 +0000)
committerbenoit <benoit@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Tue, 25 Mar 2008 14:48:18 +0000 (14:48 +0000)
Patch by Andy Gocke (agocke gmail com)

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@12581 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavcodec/parser.c

index 4926128a6eb14bde1e3e00eb99aa9baf02c0b45f..20f0031780da7b92d407663481136d79317c149e 100644 (file)
@@ -224,7 +224,7 @@ void av_parser_close(AVCodecParserContext *s)
 
 /**
  * combines the (truncated) bitstream to a complete frame
- * @returns -1 if no complete frame could be created
+ * @returns -1 if no complete frame could be created, AVERROR(ENOMEM) if there was a memory allocation error
  */
 int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
 {
@@ -249,8 +249,11 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s
 
     /* copy into buffer end return */
     if(next == END_NOT_FOUND){
-        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+        void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
 
+        if(!new_buffer)
+            return AVERROR(ENOMEM);
+        pc->buffer = new_buffer;
         memcpy(&pc->buffer[pc->index], *buf, *buf_size);
         pc->index += *buf_size;
         return -1;
@@ -261,8 +264,11 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s
 
     /* append to buffer */
     if(pc->index){
-        pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+        void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
 
+        if(!new_buffer)
+            return AVERROR(ENOMEM);
+        pc->buffer = new_buffer;
         memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
         pc->index = 0;
         *buf= pc->buffer;