Browse code

qt-faststart: Use the error_out cleanup code path for all error returns

Originally committed as revision 23125 to svn://svn.ffmpeg.org/ffmpeg/trunk

Martin Storsjö authored on 2010/05/14 04:17:15
Showing 1 changed files
... ...
@@ -75,14 +75,14 @@
75 75
 
76 76
 int main(int argc, char *argv[])
77 77
 {
78
-    FILE *infile;
79
-    FILE *outfile;
78
+    FILE *infile  = NULL;
79
+    FILE *outfile = NULL;
80 80
     unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
81 81
     uint32_t atom_type = 0;
82 82
     uint64_t atom_size = 0;
83 83
     uint64_t atom_offset = 0;
84 84
     uint64_t last_offset;
85
-    unsigned char *moov_atom;
85
+    unsigned char *moov_atom = NULL;
86 86
     unsigned char *ftyp_atom = 0;
87 87
     uint64_t moov_atom_size;
88 88
     uint64_t ftyp_atom_size = 0;
... ...
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
101 101
     infile = fopen(argv[1], "rb");
102 102
     if (!infile) {
103 103
         perror(argv[1]);
104
-        return 1;
104
+        goto error_out;
105 105
     }
106 106
 
107 107
     /* traverse through the atoms in the file to make sure that 'moov' is
... ...
@@ -121,15 +121,12 @@ int main(int argc, char *argv[])
121 121
             if (!ftyp_atom) {
122 122
                 printf ("could not allocate %"PRIu64" byte for ftyp atom\n",
123 123
                         atom_size);
124
-                fclose(infile);
125
-                return 1;
124
+                goto error_out;
126 125
             }
127 126
             fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
128 127
             if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
129 128
                 perror(argv[1]);
130
-                free(ftyp_atom);
131
-                fclose(infile);
132
-                return 1;
129
+                goto error_out;
133 130
             }
134 131
             start_offset = ftello(infile);
135 132
         } else {
... ...
@@ -184,30 +181,23 @@ int main(int argc, char *argv[])
184 184
     if (!moov_atom) {
185 185
         printf ("could not allocate %"PRIu64" byte for moov atom\n",
186 186
             atom_size);
187
-        free(ftyp_atom);
188
-        fclose(infile);
189
-        return 1;
187
+        goto error_out;
190 188
     }
191 189
     if (fread(moov_atom, atom_size, 1, infile) != 1) {
192 190
         perror(argv[1]);
193
-        free(moov_atom);
194
-        free(ftyp_atom);
195
-        fclose(infile);
196
-        return 1;
191
+        goto error_out;
197 192
     }
198 193
 
199 194
     /* this utility does not support compressed atoms yet, so disqualify
200 195
      * files with compressed QT atoms */
201 196
     if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
202 197
         printf ("this utility does not support compressed moov atoms yet\n");
203
-        free(moov_atom);
204
-        free(ftyp_atom);
205
-        fclose(infile);
206
-        return 1;
198
+        goto error_out;
207 199
     }
208 200
 
209 201
     /* close; will be re-opened later */
210 202
     fclose(infile);
203
+    infile = NULL;
211 204
 
212 205
     /* crawl through the moov chunk in search of stco or co64 atoms */
213 206
     for (i = 4; i < moov_atom_size - 4; i++) {
... ...
@@ -217,9 +207,7 @@ int main(int argc, char *argv[])
217 217
             atom_size = BE_32(&moov_atom[i - 4]);
218 218
             if (i + atom_size - 4 > moov_atom_size) {
219 219
                 printf (" bad atom size\n");
220
-                free(moov_atom);
221
-                free(ftyp_atom);
222
-                return 1;
220
+                goto error_out;
223 221
             }
224 222
             offset_count = BE_32(&moov_atom[i + 8]);
225 223
             for (j = 0; j < offset_count; j++) {
... ...
@@ -236,9 +224,7 @@ int main(int argc, char *argv[])
236 236
             atom_size = BE_32(&moov_atom[i - 4]);
237 237
             if (i + atom_size - 4 > moov_atom_size) {
238 238
                 printf (" bad atom size\n");
239
-                free(moov_atom);
240
-                free(ftyp_atom);
241
-                return 1;
239
+                goto error_out;
242 240
             }
243 241
             offset_count = BE_32(&moov_atom[i + 8]);
244 242
             for (j = 0; j < offset_count; j++) {
... ...
@@ -261,9 +247,7 @@ int main(int argc, char *argv[])
261 261
     infile = fopen(argv[1], "rb");
262 262
     if (!infile) {
263 263
         perror(argv[1]);
264
-        free(moov_atom);
265
-        free(ftyp_atom);
266
-        return 1;
264
+        goto error_out;
267 265
     }
268 266
 
269 267
     if (start_offset > 0) { /* seek after ftyp atom */
... ...
@@ -274,10 +258,7 @@ int main(int argc, char *argv[])
274 274
     outfile = fopen(argv[2], "wb");
275 275
     if (!outfile) {
276 276
         perror(argv[2]);
277
-        fclose(outfile);
278
-        free(moov_atom);
279
-        free(ftyp_atom);
280
-        return 1;
277
+        goto error_out;
281 278
     }
282 279
 
283 280
     /* dump the same ftyp atom */
... ...
@@ -324,7 +305,9 @@ int main(int argc, char *argv[])
324 324
     return 0;
325 325
 
326 326
 error_out:
327
+    if (infile)
327 328
     fclose(infile);
329
+    if (outfile)
328 330
     fclose(outfile);
329 331
     free(moov_atom);
330 332
     free(ftyp_atom);