various: use DEFINE_ARRAY_FREE_FUNC

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-10 15:08:03 +02:00
parent 2a23e43f70
commit 79f90f4ae0
8 changed files with 25 additions and 45 deletions
+4 -7
View 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;
+5 -8
View 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,
+6 -11
View 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:
+1 -1
View 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);
+6 -8
View 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);
static void install_change_done(InstallChange *change) {
assert(change);
FOREACH_ARRAY(i, changes, n_changes) {
free(i->path);
free(i->source);
}
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);
+1 -1
View 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(
+1 -8
View 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) {
+1 -1
View 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(