diff mbox series

[FFmpeg-devel,4/5] fftools/ffmpeg_opt: Fix leak on error

Message ID AS8P250MB07447A64B2CE58CAC1DE80DA8F3CA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 8bb1bcf47d532c6f67dbc444bb7893f6f94f4c8a
Headers show
Series [FFmpeg-devel,1/5] fftools/ffmpeg_mux_init: Fix leak on error | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt July 22, 2023, 7:11 p.m. UTC
Fixes Coverity id #1539096.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 fftools/ffmpeg_opt.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index f7606ae6f6..1860e9d329 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -401,13 +401,14 @@  static int opt_map(void *optctx, const char *opt, const char *arg)
 
         ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
         if (ret < 0)
-            return ret;
+            goto fail;
 
         m = &o->stream_maps[o->nb_stream_maps - 1];
         m->linklabel = av_get_token(&c, "]");
         if (!m->linklabel) {
             av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
-            return AVERROR(EINVAL);
+            ret = AVERROR(EINVAL);
+            goto fail;
         }
     } else {
         if (allow_unused = strchr(map, '?'))
@@ -415,7 +416,8 @@  static int opt_map(void *optctx, const char *opt, const char *arg)
         file_idx = strtol(map, &p, 0);
         if (file_idx >= nb_input_files || file_idx < 0) {
             av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
-            return AVERROR(EINVAL);
+            ret = AVERROR(EINVAL);
+            goto fail;
         }
         if (negative)
             /* disable some already defined maps */
@@ -438,7 +440,7 @@  static int opt_map(void *optctx, const char *opt, const char *arg)
                 }
                 ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
                 if (ret < 0)
-                    return ret;
+                    goto fail;
 
                 m = &o->stream_maps[o->nb_stream_maps - 1];
 
@@ -453,16 +455,19 @@  static int opt_map(void *optctx, const char *opt, const char *arg)
         } else if (disabled) {
             av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
                                        "To ignore this, add a trailing '?' to the map.\n", arg);
-            return AVERROR(EINVAL);
+            ret = AVERROR(EINVAL);
+            goto fail;
         } else {
             av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
                                        "To ignore this, add a trailing '?' to the map.\n", arg);
-            return AVERROR(EINVAL);
+            ret = AVERROR(EINVAL);
+            goto fail;
         }
     }
-
+    ret = 0;
+fail:
     av_freep(&map);
-    return 0;
+    return ret;
 }
 
 static int opt_attach(void *optctx, const char *opt, const char *arg)