]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/execute: introduce exec_command_free
authorMike Yuan <me@yhndnzj.com>
Wed, 10 Apr 2024 20:10:36 +0000 (04:10 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 10 Apr 2024 20:44:57 +0000 (04:44 +0800)
src/core/execute.c
src/core/execute.h

index 2ddfa7423def0e1c82c3623b44cf549b52802760..0cfbf79946143c79a3a49b081f885045be8a3bd0 100644 (file)
@@ -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;
 }
index 21dddedffef7b8e48f4f2b37858981c947487a34..c41f9cbec2fc89a483eee9e6c3408ca05ba54b58 100644 (file)
@@ -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_;