From: David Tardon Date: Mon, 14 Aug 2023 14:07:46 +0000 (+0200) Subject: tree-wide: use LIST_CLEAR() X-Git-Tag: v255-rc1~698^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9aad490e53888c39434f668df833e0e179f144b0;p=thirdparty%2Fsystemd.git tree-wide: use LIST_CLEAR() --- diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 2ccfcbad72e..91ef33b12c9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -247,11 +247,7 @@ void cgroup_context_remove_bpf_foreign_program(CGroupContext *c, CGroupBPFForeig void cgroup_context_remove_socket_bind(CGroupSocketBindItem **head) { assert(head); - while (*head) { - CGroupSocketBindItem *h = *head; - LIST_REMOVE(socket_bind_items, *head, h); - free(h); - } + LIST_CLEAR(socket_bind_items, *head, free); } void cgroup_context_done(CGroupContext *c) { diff --git a/src/core/socket.c b/src/core/socket.c index 023c0ba3882..74d77692819 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -134,14 +134,9 @@ SocketPort *socket_port_free(SocketPort *p) { } void socket_free_ports(Socket *s) { - SocketPort *p; - assert(s); - while ((p = s->ports)) { - LIST_REMOVE(port, s->ports, p); - socket_port_free(p); - } + LIST_CLEAR(port, s->ports, socket_port_free); } static void socket_done(Unit *u) { diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index 890c1462950..839c9a9ee6f 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -99,19 +99,8 @@ static sd_radv *radv_free(sd_radv *ra) { if (!ra) return NULL; - while (ra->prefixes) { - sd_radv_prefix *p = ra->prefixes; - - LIST_REMOVE(prefix, ra->prefixes, p); - sd_radv_prefix_unref(p); - } - - while (ra->route_prefixes) { - sd_radv_route_prefix *p = ra->route_prefixes; - - LIST_REMOVE(prefix, ra->route_prefixes, p); - sd_radv_route_prefix_unref(p); - } + LIST_CLEAR(prefix, ra->prefixes, sd_radv_prefix_unref); + LIST_CLEAR(prefix, ra->route_prefixes, sd_radv_route_prefix_unref); free(ra->rdnss); free(ra->dnssl); diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index ffc6452bbfe..0e992f9ad1b 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -35,14 +35,9 @@ static void wireguard_resolve_endpoints(NetDev *netdev); static int peer_resolve_endpoint(WireguardPeer *peer); static void wireguard_peer_clear_ipmasks(WireguardPeer *peer) { - WireguardIPmask *mask; - assert(peer); - while ((mask = peer->ipmasks)) { - LIST_REMOVE(ipmasks, peer->ipmasks, mask); - free(mask); - } + LIST_CLEAR(ipmasks, peer->ipmasks, free); } static WireguardPeer* wireguard_peer_free(WireguardPeer *peer) { diff --git a/src/nspawn/nspawn-expose-ports.c b/src/nspawn/nspawn-expose-ports.c index b35f8b6a9ba..56440684467 100644 --- a/src/nspawn/nspawn-expose-ports.c +++ b/src/nspawn/nspawn-expose-ports.c @@ -73,12 +73,7 @@ int expose_port_parse(ExposePort **l, const char *s) { } void expose_port_free_all(ExposePort *p) { - - while (p) { - ExposePort *q = p; - LIST_REMOVE(ports, p, q); - free(q); - } + LIST_CLEAR(ports, p, free); } int expose_port_flush(FirewallContext **fw_ctx, ExposePort* l, int af, union in_addr_union *exposed) { diff --git a/src/shared/bus-polkit.c b/src/shared/bus-polkit.c index 2d9e521fc50..a68367d50b5 100644 --- a/src/shared/bus-polkit.c +++ b/src/shared/bus-polkit.c @@ -204,8 +204,6 @@ typedef struct AsyncPolkitQuery { } AsyncPolkitQuery; static AsyncPolkitQuery *async_polkit_query_free(AsyncPolkitQuery *q) { - AsyncPolkitQueryAction *a; - if (!q) return NULL; @@ -220,8 +218,7 @@ static AsyncPolkitQuery *async_polkit_query_free(AsyncPolkitQuery *q) { sd_event_source_disable_unref(q->defer_event_source); - while ((a = LIST_POP(authorized, q->authorized_actions))) - async_polkit_query_action_free(a); + LIST_CLEAR(authorized, q->authorized_actions, async_polkit_query_action_free); async_polkit_query_action_free(q->denied_action); async_polkit_query_action_free(q->error_action); diff --git a/src/shared/open-file.c b/src/shared/open-file.c index 3402518555b..906a141d60d 100644 --- a/src/shared/open-file.c +++ b/src/shared/open-file.c @@ -132,12 +132,7 @@ OpenFile *open_file_free(OpenFile *of) { } void open_file_free_many(OpenFile **head) { - OpenFile *of; - - while ((of = *head)) { - LIST_REMOVE(open_files, *head, of); - of = open_file_free(of); - } + LIST_CLEAR(open_files, *head, open_file_free); } static const char * const open_file_flags_table[_OPENFILE_MAX] = { diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 41c2daf02bd..28068c686e3 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -473,12 +473,7 @@ static void varlink_clear(Varlink *v) { v->pushed_fds = mfree(v->pushed_fds); v->n_pushed_fds = 0; - while (v->output_queue) { - VarlinkJsonQueueItem *q = v->output_queue; - - LIST_REMOVE(queue, v->output_queue, q); - varlink_json_queue_item_free(q); - } + LIST_CLEAR(queue, v->output_queue, varlink_json_queue_item_free); v->output_queue_tail = NULL; v->event = sd_event_unref(v->event); diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 6422550af48..38cd4256e11 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -279,24 +279,14 @@ typedef struct UnitStatusInfo { } UnitStatusInfo; static void unit_status_info_free(UnitStatusInfo *info) { - ExecStatusInfo *p; - UnitCondition *c; - strv_free(info->documentation); strv_free(info->dropin_paths); strv_free(info->triggered_by); strv_free(info->triggers); strv_free(info->listen); - while ((c = info->conditions)) { - LIST_REMOVE(conditions, info->conditions, c); - unit_condition_free(c); - } - - while ((p = info->exec_status_info_list)) { - LIST_REMOVE(exec_status_info_list, info->exec_status_info_list, p); - exec_status_info_free(p); - } + LIST_CLEAR(conditions, info->conditions, unit_condition_free); + LIST_CLEAR(exec_status_info_list, info->exec_status_info_list, exec_status_info_free); } static void format_active_state(const char *active_state, const char **active_on, const char **active_off) { diff --git a/src/sysupdate/sysupdate-pattern.c b/src/sysupdate/sysupdate-pattern.c index c9e2067c58e..6822d7eda22 100644 --- a/src/sysupdate/sysupdate-pattern.c +++ b/src/sysupdate/sysupdate-pattern.c @@ -36,10 +36,7 @@ struct PatternElement { }; static PatternElement *pattern_element_free_all(PatternElement *e) { - PatternElement *p; - - while ((p = LIST_POP(elements, e))) - free(p); + LIST_CLEAR(elements, e, free); return NULL; } diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index ad1d492d6bb..5ac7c9f8b24 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -115,8 +115,6 @@ static UnitStatusInfo *unit_status_info_free(UnitStatusInfo *p) { DEFINE_TRIVIAL_CLEANUP_FUNC(UnitStatusInfo*, unit_status_info_free); static void context_clear(Context *c) { - UnitStatusInfo *p; - assert(c); free(c->zone); @@ -125,10 +123,7 @@ static void context_clear(Context *c) { sd_bus_slot_unref(c->slot_job_removed); - while ((p = c->units)) { - LIST_REMOVE(units, c->units, p); - unit_status_info_free(p); - } + LIST_CLEAR(units, c->units, unit_status_info_free); } static int context_add_ntp_service(Context *c, const char *s, const char *source) {