mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
fix(pkg/rootless): avoid memleak during init() contructor.
`argv[0]`, ie: the full buffer allocated by `get_cmd_line_args`, was going to be freed only if `can_use_shortcut()` was called. Instead, let `init()` always manage `argv0` lifecycle. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
This commit is contained in:
@ -364,7 +364,6 @@ get_cmd_line_args (int *argc_out)
|
||||
static bool
|
||||
can_use_shortcut (char **argv)
|
||||
{
|
||||
cleanup_free char *argv0 = NULL;
|
||||
bool ret = true;
|
||||
int argc;
|
||||
|
||||
@ -372,8 +371,6 @@ can_use_shortcut (char **argv)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
argv0 = argv[0];
|
||||
|
||||
if (strstr (argv[0], "podman") == NULL)
|
||||
return false;
|
||||
|
||||
@ -439,6 +436,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 +494,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);
|
||||
|
Reference in New Issue
Block a user