From: Antonio Alvarez Feijoo Date: Wed, 10 Jan 2024 14:05:50 +0000 (+0100) Subject: repart: fix memory leak X-Git-Tag: v256-rc1~1207 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecb4c5a63e399f33516ba08bb0a4802924dc194d;p=thirdparty%2Fsystemd.git repart: fix memory leak With the `--image` option, if `arg_node` is NULL, it's being assigned via `strdup`. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 2fee79f33ef..9b6b8a5a14c 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -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),