From: Mike Yuan Date: Wed, 10 Apr 2024 19:57:34 +0000 (+0800) Subject: core/dbus-execute: fix potential memory leak X-Git-Tag: v256-rc1~229^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F32210%2Fhead;p=thirdparty%2Fsystemd.git core/dbus-execute: fix potential memory leak --- diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 5970aef769f..b3cea73c434 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1354,29 +1354,28 @@ int bus_set_transient_exec_command( return r; if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - ExecCommand *c; + _cleanup_(exec_command_freep) ExecCommand *c = NULL; - c = new0(ExecCommand, 1); + c = new(ExecCommand, 1); if (!c) return -ENOMEM; - c->path = strdup(path); - if (!c->path) { - free(c); - return -ENOMEM; - } + *c = (ExecCommand) { + .argv = TAKE_PTR(argv), + }; - c->argv = TAKE_PTR(argv); + r = path_simplify_alloc(path, &c->path); + if (r < 0) + return r; if (ex_prop) { r = exec_command_flags_from_strv(ex_opts, &c->flags); if (r < 0) return r; - } else - c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; + } else if (b) + c->flags |= EXEC_COMMAND_IGNORE_FAILURE; - path_simplify(c->path); - exec_command_append_list(exec_command, c); + exec_command_append_list(exec_command, TAKE_PTR(c)); } n++;