summaryrefslogtreecommitdiff
path: root/libavcodec/parser.c
diff options
context:
space:
mode:
authorAndy Gocke <agocke@gmail.com>2008-03-25 14:48:18 +0000
committerBenoit Fouet <benoit.fouet@free.fr>2008-03-25 14:48:18 +0000
commit1f96bafb27a1a201dc0bfd299bea7c0a2d8370dc (patch)
tree190b1978679ac52a84f49bfbc1b72e4710e4b8b6 /libavcodec/parser.c
parent28c47a423b6266a6cfaabff149b9bfe1e7401e9b (diff)
Return an error when realloc fails.
Patch by Andy Gocke (agocke gmail com) Originally committed as revision 12581 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/parser.c')
-rw-r--r--libavcodec/parser.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 4926128a6e..20f0031780 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -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;