summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2011-03-29 21:44:19 -0400
committerJohn Koleszar <jkoleszar@google.com>2011-03-30 06:37:02 -0400
commit26b6a3b088682a86632babffbd9d6749b609bdd7 (patch)
tree9ba4eef024f8ab401a3b3976640d3af4fea948f1
parent0e43668546010bf0a9ece398effb37beca5dbea5 (diff)
downloadlibvpx-26b6a3b088682a86632babffbd9d6749b609bdd7.tar
libvpx-26b6a3b088682a86632babffbd9d6749b609bdd7.tar.gz
libvpx-26b6a3b088682a86632babffbd9d6749b609bdd7.tar.bz2
libvpx-26b6a3b088682a86632babffbd9d6749b609bdd7.zip
vpxenc: die on realloc failures
Identified as a possible cause of issue #308, the code was silently ignoring realloc failures, which would lead to corruption, memory leaks, and likely a crash. The best we can do in this case is die gracefully. Change-Id: Ie5f6a853d367015be5b9712bd742778f3baeefd9
-rwxr-xr-xvpxenc.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/vpxenc.c b/vpxenc.c
index 6c13cd1bd..39256b665 100755
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -236,7 +236,13 @@ void stats_write(stats_io_t *stats, const void *pkt, size_t len)
stats->buf_ptr = new_ptr + (stats->buf_ptr - (char *)stats->buf.buf);
stats->buf.buf = new_ptr;
stats->buf_alloc_sz = new_sz;
- } /* else ... */
+ }
+ else
+ {
+ fprintf(stderr,
+ "\nFailed to realloc firstpass stats buffer.\n");
+ exit(EXIT_FAILURE);
+ }
}
memcpy(stats->buf_ptr, pkt, len);
@@ -698,10 +704,18 @@ write_webm_block(EbmlGlobal *glob,
/* Save a cue point if this is a keyframe. */
if(is_keyframe)
{
- struct cue_entry *cue;
+ struct cue_entry *cue, *new_cue_list;
+
+ new_cue_list = realloc(glob->cue_list,
+ (glob->cues+1) * sizeof(struct cue_entry));
+ if(new_cue_list)
+ glob->cue_list = new_cue_list;
+ else
+ {
+ fprintf(stderr, "\nFailed to realloc cue list.\n");
+ exit(EXIT_FAILURE);
+ }
- glob->cue_list = realloc(glob->cue_list,
- (glob->cues+1) * sizeof(struct cue_entry));
cue = &glob->cue_list[glob->cues];
cue->time = glob->cluster_timecode;
cue->loc = glob->cluster_pos;