Browse code

ffprobe: fix memleaks on errors

Found-by: Andreas Cadhalpun <andreas.cadhalpun@googlemail.com>
Reviewed-by: Stefano Sabatini <stefasab@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2015/01/21 13:35:50
Showing 1 changed files
... ...
@@ -2398,6 +2398,7 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
2398 2398
         print_error(filename, err);
2399 2399
         return err;
2400 2400
     }
2401
+    *fmt_ctx_ptr = fmt_ctx;
2401 2402
     if (scan_all_pmts_set)
2402 2403
         av_dict_set(&format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
2403 2404
     if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
... ...
@@ -2409,14 +2410,17 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
2409 2409
     opts = setup_find_stream_info_opts(fmt_ctx, codec_opts);
2410 2410
     orig_nb_streams = fmt_ctx->nb_streams;
2411 2411
 
2412
-    if ((err = avformat_find_stream_info(fmt_ctx, opts)) < 0) {
2413
-        print_error(filename, err);
2414
-        return err;
2415
-    }
2412
+    err = avformat_find_stream_info(fmt_ctx, opts);
2413
+
2416 2414
     for (i = 0; i < orig_nb_streams; i++)
2417 2415
         av_dict_free(&opts[i]);
2418 2416
     av_freep(&opts);
2419 2417
 
2418
+    if (err < 0) {
2419
+        print_error(filename, err);
2420
+        return err;
2421
+    }
2422
+
2420 2423
     av_dump_format(fmt_ctx, 0, filename, 0);
2421 2424
 
2422 2425
     /* bind a decoder to each input stream */
... ...
@@ -2466,7 +2470,7 @@ static void close_input_file(AVFormatContext **ctx_ptr)
2466 2466
 
2467 2467
 static int probe_file(WriterContext *wctx, const char *filename)
2468 2468
 {
2469
-    AVFormatContext *fmt_ctx;
2469
+    AVFormatContext *fmt_ctx = NULL;
2470 2470
     int ret, i;
2471 2471
     int section_id;
2472 2472
 
... ...
@@ -2475,7 +2479,7 @@ static int probe_file(WriterContext *wctx, const char *filename)
2475 2475
 
2476 2476
     ret = open_input_file(&fmt_ctx, filename);
2477 2477
     if (ret < 0)
2478
-        return ret;
2478
+        goto end;
2479 2479
 
2480 2480
 #define CHECK_END if (ret < 0) goto end
2481 2481
 
... ...
@@ -2533,7 +2537,8 @@ static int probe_file(WriterContext *wctx, const char *filename)
2533 2533
     }
2534 2534
 
2535 2535
 end:
2536
-    close_input_file(&fmt_ctx);
2536
+    if (fmt_ctx)
2537
+        close_input_file(&fmt_ctx);
2537 2538
     av_freep(&nb_streams_frames);
2538 2539
     av_freep(&nb_streams_packets);
2539 2540
     av_freep(&selected_streams);