]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: fix memory leak in arg_exclude_prefixes
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Mon, 8 Jan 2024 15:08:26 +0000 (16:08 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 8 Jan 2024 18:08:42 +0000 (19:08 +0100)
When using the `--image` or `-E` options, `arg_exclude_prefixes` is extended via
the `exclude_default_prefixes` function, which calls `strv_extend_strv`, adding
values using `strdup` that must be freed on exit.

Also changing `arg_include_prefixes` to use the same model, although there is no
leak here.

src/tmpfiles/tmpfiles.c

index aa6e72207f36fcdd3015d941c7b72e0ff0f446ba..94339d81631468da79f617e724b9e1cd482ddc53 100644 (file)
@@ -218,8 +218,8 @@ typedef struct Context {
         Set *unix_sockets;
 } Context;
 
-STATIC_DESTRUCTOR_REGISTER(arg_include_prefixes, freep);
-STATIC_DESTRUCTOR_REGISTER(arg_exclude_prefixes, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_include_prefixes, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_exclude_prefixes, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
@@ -4129,12 +4129,12 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_PREFIX:
-                        if (strv_push(&arg_include_prefixes, optarg) < 0)
+                        if (strv_extend(&arg_include_prefixes, optarg) < 0)
                                 return log_oom();
                         break;
 
                 case ARG_EXCLUDE_PREFIX:
-                        if (strv_push(&arg_exclude_prefixes, optarg) < 0)
+                        if (strv_extend(&arg_exclude_prefixes, optarg) < 0)
                                 return log_oom();
                         break;