changeset 36538:98b2752facfd

vobsub: Simplify and fix memleak.
author reimar
date Sun, 19 Jan 2014 13:14:41 +0000
parents 3b2228019b6a
children 88676698b409
files sub/vobsub.c
diffstat 1 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sub/vobsub.c	Sun Jan 19 12:06:04 2014 +0000
+++ b/sub/vobsub.c	Sun Jan 19 13:14:41 2014 +0000
@@ -1229,12 +1229,13 @@
                       unsigned int orig_width, unsigned int orig_height,
                       const char *id, unsigned int index)
 {
-    vobsub_out_t *result = NULL;
-    char *filename;
-    filename = malloc(strlen(basename) + 5);
-    if (filename) {
-        result = malloc(sizeof(vobsub_out_t));
-        if (result) {
+    vobsub_out_t *result = calloc(1, sizeof(*result));
+    char *filename = malloc(strlen(basename) + 5);
+    if (!filename || !result) {
+        free(filename);
+        free(result);
+        return NULL;
+    }
             result->aid = index;
             strcpy(filename, basename);
             strcat(filename, ".sub");
@@ -1256,8 +1257,6 @@
             } else
                 perror("Error: vobsub_out_open index file open failed");
             free(filename);
-        }
-    }
     return result;
 }