]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: use DEFINE_ARRAY_FREE_FUNC 41559/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 8 Apr 2026 21:04:47 +0000 (23:04 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 10 Apr 2026 13:08:03 +0000 (15:08 +0200)
src/core/exec-invoke.c
src/libsystemd/sd-journal/journal-vacuum.c
src/portable/portable.c
src/portable/portable.h
src/shared/install.c
src/shared/install.h
src/shared/mount-util.c
src/shared/mount-util.h

index b91a964cdd6abdc1acb037c49be62aebab8bdd24..fef2c3a0f2c5c04a251fd8ef2e3dd56356467b30 100644 (file)
@@ -1086,15 +1086,12 @@ static int enforce_user(
 
 #if HAVE_PAM
 
-static void pam_response_free_array(struct pam_response *responses, size_t n_responses) {
-        assert(responses || n_responses == 0);
-
-        FOREACH_ARRAY(resp, responses, n_responses)
-                erase_and_free(resp->resp);
-
-        free(responses);
+static void pam_response_done(struct pam_response *response) {
+        erase_and_free(ASSERT_PTR(response)->resp);
 }
 
+static DEFINE_ARRAY_FREE_FUNC(pam_response_free_array, struct pam_response, pam_response_done);
+
 typedef struct AskPasswordConvData {
         const ExecContext *context;
         const ExecParameters *params;
index e88ba0e5396561e728cf09021b30abb493516378..a49c073b3e57241af0e9f146947dcc4020e47907 100644 (file)
@@ -49,16 +49,13 @@ static int vacuum_info_compare(const VacuumInfo *a, const VacuumInfo *b) {
         return strcmp(a->filename, b->filename);
 }
 
-static void vacuum_info_array_free(VacuumInfo *list, size_t n) {
-        if (!list)
-                return;
-
-        FOREACH_ARRAY(i, list, n)
-                free(i->filename);
-
-        free(list);
+static void vacuum_info_done(VacuumInfo *info) {
+        assert(info);
+        info->filename = mfree(info->filename);
 }
 
+static DEFINE_ARRAY_FREE_FUNC(vacuum_info_array_free, VacuumInfo, vacuum_info_done);
+
 static void patch_realtime(
                 int fd,
                 const char *fn,
index bae23b1a5115e83acc073a289148b628dadead32..12a14cbf4240a60a325f7cabdc7f85e4ce43eb6a 100644 (file)
@@ -1271,19 +1271,14 @@ static int portable_changes_add_with_prefix(
         return portable_changes_add(changes, n_changes, type_or_errno, path, source);
 }
 
-void portable_changes_free(PortableChange *changes, size_t n_changes) {
-        size_t i;
-
-        assert(changes || n_changes == 0);
-
-        for (i = 0; i < n_changes; i++) {
-                free(changes[i].path);
-                free(changes[i].source);
-        }
-
-        free(changes);
+static void portable_change_done(PortableChange *change) {
+        assert(change);
+        change->path = mfree(change->path);
+        change->source = mfree(change->source);
 }
 
+DEFINE_ARRAY_FREE_FUNC(portable_changes_free, PortableChange, portable_change_done);
+
 static const char *root_setting_from_image(ImageType type) {
         switch (type) {
         case IMAGE_DIRECTORY:
index 5065babaab24c949c191c211f5c6585649e53a6e..af5ef3ba652a2b3a7da71f53389caaa42b8db901 100644 (file)
@@ -112,7 +112,7 @@ int portable_get_state(
 
 int portable_get_profiles(RuntimeScope scope, char ***ret);
 
-void portable_changes_free(PortableChange *changes, size_t n_changes);
+void portable_changes_free(PortableChange *array, size_t n);
 
 DECLARE_STRING_TABLE_LOOKUP(portable_change_type, int);
 
index 23982241766f92a12a450e77414a5d8831331eb2..149faed711a70d2ffc28fd802da5c72438042a88 100644 (file)
@@ -319,17 +319,15 @@ InstallChangeType install_changes_add(
         return type;
 }
 
-void install_changes_free(InstallChange *changes, size_t n_changes) {
-        assert(changes || n_changes == 0);
-
-        FOREACH_ARRAY(i, changes, n_changes) {
-                free(i->path);
-                free(i->source);
-        }
+static void install_change_done(InstallChange *change) {
+        assert(change);
 
-        free(changes);
+        change->path = mfree(change->path);
+        change->source = mfree(change->source);
 }
 
+DEFINE_ARRAY_FREE_FUNC(install_changes_free, InstallChange, install_change_done);
+
 static void install_change_dump_success(const InstallChange *change) {
         assert(change);
         assert(change->path);
index ad5803e32168e3d1095bfda42c0333a0b0829752..f184b7191cad759c14ea79550f23951e9eb8a963 100644 (file)
@@ -202,7 +202,7 @@ static inline int unit_file_exists(RuntimeScope scope, const LookupPaths *lp, co
 int unit_file_get_list(RuntimeScope scope, const char *root_dir, char * const *states, char * const *patterns, Hashmap **ret);
 
 InstallChangeType install_changes_add(InstallChange **changes, size_t *n_changes, InstallChangeType type, const char *path, const char *source);
-void install_changes_free(InstallChange *changes, size_t n_changes);
+void install_changes_free(InstallChange *array, size_t n);
 
 int install_change_dump_error(const InstallChange *change, char **ret_errmsg, const char **ret_bus_error);
 int install_changes_dump(
index f7bba5d080c859d4d0aae42b5afa3997cd2eaa3f..45ffd9113b7e62d0b6a1131c76c9f6c70385040e 100644 (file)
@@ -1748,14 +1748,7 @@ static void sub_mount_clear(SubMount *s) {
         s->mount_fd = safe_close(s->mount_fd);
 }
 
-void sub_mount_array_free(SubMount *s, size_t n) {
-        assert(s || n == 0);
-
-        for (size_t i = 0; i < n; i++)
-                sub_mount_clear(s + i);
-
-        free(s);
-}
+DEFINE_ARRAY_FREE_FUNC(sub_mount_array_free, SubMount, sub_mount_clear);
 
 #if HAVE_LIBMOUNT
 static int sub_mount_compare(const SubMount *a, const SubMount *b) {
index 768aacf09c401cdb2131c213aafaad32126b70c2..b178bf7bac28e35ae8d5939f2cb71c6b96afe213 100644 (file)
@@ -8,7 +8,7 @@ typedef struct SubMount {
         int mount_fd;
 } SubMount;
 
-void sub_mount_array_free(SubMount *s, size_t n);
+void sub_mount_array_free(SubMount *array, size_t n);
 
 int get_sub_mounts(const char *prefix, SubMount **ret_mounts, size_t *ret_n_mounts);
 int bind_mount_submounts(