diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c index ddb97b3346..478e3577b4 100644 --- a/pkg/rootless/rootless_linux.c +++ b/pkg/rootless/rootless_linux.c @@ -439,6 +439,7 @@ static void __attribute__((constructor)) init() const char *listen_fds; const char *listen_fdnames; cleanup_free char **argv = NULL; + cleanup_free char *argv0 = NULL; cleanup_dir DIR *d = NULL; int argc; @@ -496,6 +497,8 @@ static void __attribute__((constructor)) init() fprintf(stderr, "cannot retrieve cmd line"); _exit (EXIT_FAILURE); } + // Even if unused, this is needed to ensure we properly free the memory + argv0 = argv[0]; if (geteuid () != 0 || getenv ("_CONTAINERS_USERNS_CONFIGURED") == NULL) do_preexec_hooks(argv, argc); @@ -525,6 +528,8 @@ static void __attribute__((constructor)) init() xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR"); if (geteuid () != 0 && xdg_runtime_dir && xdg_runtime_dir[0] && can_use_shortcut (argv)) { + // It was freed by can_use_shortcut() call + argv0 = NULL; cleanup_free char *cwd = NULL; cleanup_close int userns_fd = -1; cleanup_close int mntns_fd = -1;