repart: fix memory leak

With the `--image` option, if `arg_node` is NULL, it's being assigned via
`strdup`.
This commit is contained in:
Antonio Alvarez Feijoo
2024-01-10 15:05:50 +01:00
committed by Luca Boccassi
parent 52e5b950dc
commit ecb4c5a63e

View 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),