ismindex: Check the return value of allocations
authorMartin Storsjö <martin@martin.st>
Wed, 13 Mar 2013 12:13:46 +0000 (14:13 +0200)
committerMartin Storsjö <martin@martin.st>
Wed, 13 Mar 2013 18:41:25 +0000 (20:41 +0200)
Signed-off-by: Martin Storsjö <martin@martin.st>
tools/ismindex.c

index 89b33e5..ad1f3a8 100644 (file)
@@ -300,10 +300,21 @@ static int handle_file(struct Tracks *tracks, const char *file, int split)
         tracks->duration = ctx->duration;
 
     for (i = 0; i < ctx->nb_streams; i++) {
+        struct Track **temp;
         AVStream *st = ctx->streams[i];
         track = av_mallocz(sizeof(*track));
-        tracks->tracks = av_realloc(tracks->tracks,
-                                    sizeof(*tracks->tracks) * (tracks->nb_tracks + 1));
+        if (!track) {
+            err = AVERROR(ENOMEM);
+            goto fail;
+        }
+        temp = av_realloc(tracks->tracks,
+                          sizeof(*tracks->tracks) * (tracks->nb_tracks + 1));
+        if (!temp) {
+            av_free(track);
+            err = AVERROR(ENOMEM);
+            goto fail;
+        }
+        tracks->tracks = temp;
         tracks->tracks[tracks->nb_tracks] = track;
 
         track->name = file;