]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: fix memory leak
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Wed, 10 Jan 2024 14:05:50 +0000 (15:05 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 10 Jan 2024 19:07:21 +0000 (19:07 +0000)
With the `--image` option, if `arg_node` is NULL, it's being assigned via
`strdup`.

src/partition/repart.c

index 2fee79f33efe80de97f7d6be5f7c43987885cbb9..9b6b8a5a14cfde6b57204589c775b2cca33933d3 100644 (file)
@@ -128,7 +128,7 @@ typedef enum FilterPartitionType {
 
 static EmptyMode arg_empty = EMPTY_UNSET;
 static bool arg_dry_run = true;
-static const char *arg_node = NULL;
+static char *arg_node = NULL;
 static char *arg_root = NULL;
 static char *arg_image = NULL;
 static char **arg_definitions = NULL;
@@ -169,6 +169,7 @@ static char **arg_copy_from = NULL;
 static char *arg_copy_source = NULL;
 static char *arg_make_ddi = NULL;
 
+STATIC_DESTRUCTOR_REGISTER(arg_node, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_definitions, strv_freep);
@@ -7040,7 +7041,11 @@ static int parse_argv(int argc, char *argv[]) {
                         return log_oom();
         }
 
-        arg_node = argc > optind ? argv[optind] : NULL;
+        if (argc > optind) {
+                arg_node = strdup(argv[optind]);
+                if (!arg_node)
+                        return log_oom();
+        }
 
         if (IN_SET(arg_empty, EMPTY_FORCE, EMPTY_REQUIRE, EMPTY_CREATE) && !arg_node && !arg_image)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),