From: Mike Yuan Date: Wed, 10 Apr 2024 20:10:36 +0000 (+0800) Subject: core/execute: introduce exec_command_free X-Git-Tag: v256-rc1~229^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f09604b0a63722e8e1bd8741a0ab6d47141cfe87;p=thirdparty%2Fsystemd.git core/execute: introduce exec_command_free --- diff --git a/src/core/execute.c b/src/core/execute.c index 2ddfa7423de..0cfbf799461 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -672,13 +672,19 @@ void exec_command_done_array(ExecCommand *c, size_t n) { exec_command_done(i); } +ExecCommand* exec_command_free(ExecCommand *c) { + if (!c) + return NULL; + + exec_command_done(c); + return mfree(c); +} + ExecCommand* exec_command_free_list(ExecCommand *c) { ExecCommand *i; - while ((i = LIST_POP(command, c))) { - exec_command_done(i); - free(i); - } + while ((i = LIST_POP(command, c))) + exec_command_free(i); return NULL; } diff --git a/src/core/execute.h b/src/core/execute.h index 21dddedffef..c41f9cbec2f 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -487,10 +487,13 @@ int exec_spawn(Unit *unit, void exec_command_done(ExecCommand *c); void exec_command_done_array(ExecCommand *c, size_t n); +ExecCommand* exec_command_free(ExecCommand *c); +DEFINE_TRIVIAL_CLEANUP_FUNC(ExecCommand*, exec_command_free); ExecCommand* exec_command_free_list(ExecCommand *c); void exec_command_free_array(ExecCommand **c, size_t n); void exec_command_reset_status_array(ExecCommand *c, size_t n); void exec_command_reset_status_list_array(ExecCommand **c, size_t n); + void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix); void exec_command_append_list(ExecCommand **l, ExecCommand *e); int exec_command_set(ExecCommand *c, const char *path, ...) _sentinel_;