firewall-util: use DEFINE_ARRAY_DONE_FUNC for netlink message cleanup

Replace the open-coded netlink_message_unref_many() function and its
DEFINE_TRIVIAL_CLEANUP_FUNC wrapper with DEFINE_ARRAY_DONE_FUNC.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-10 15:08:02 +02:00
parent 74573799ca
commit 3ed9e7cd23
+3 -17
View File
@@ -50,19 +50,7 @@ static const char* dnat_map_name(void) {
return cached;
}
static sd_netlink_message** netlink_message_unref_many(sd_netlink_message **m) {
if (!m)
return NULL;
/* This does not free array. The end of the array must be NULL. */
for (sd_netlink_message **p = m; *p; p++)
*p = sd_netlink_message_unref(*p);
return m;
}
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_netlink_message**, netlink_message_unref_many);
static DEFINE_ARRAY_DONE_FUNC(sd_netlink_message*, sd_netlink_message_unref);
static int nfnl_open_expr_container(sd_netlink_message *m, const char *name) {
int r;
@@ -736,8 +724,7 @@ static uint32_t concat_types2(enum nft_key_types a, enum nft_key_types b) {
}
static int fw_nftables_init_family(sd_netlink *nfnl, int family) {
sd_netlink_message *messages[10] = {};
_unused_ _cleanup_(netlink_message_unref_manyp) sd_netlink_message **unref = messages;
_cleanup_(sd_netlink_message_unref_many) sd_netlink_message *messages[10] = {};
size_t msgcnt = 0, ip_type_size;
uint32_t set_id = 0;
int ip_type, r;
@@ -1058,8 +1045,7 @@ static int fw_nftables_add_local_dnat_internal(
uint16_t remote_port,
const union in_addr_union *previous_remote) {
sd_netlink_message *messages[3] = {};
_unused_ _cleanup_(netlink_message_unref_manyp) sd_netlink_message **unref = messages;
_cleanup_(sd_netlink_message_unref_many) sd_netlink_message *messages[3] = {};
uint32_t data[5], key[2], dlen;
size_t msgcnt = 0;
int r;