From 6bfa590be3d7d0794641e2e9c9c35715b7fdad98 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 28 Oct 2025 15:01:21 +0000 Subject: [PATCH] [Fix] Fix memory leak in address parsing for *-any addresses In rspamd_parse_host_port_priority(), when handling '*' (any address), the GPtrArray was created with a conditional destructor: pool == NULL ? NULL : (GDestroyNotify) rspamd_inet_address_free This meant that when pool == NULL, the array had NO destructor for elements. Later, when rspamd_upstreams_add_upstream() copied addresses and called g_ptr_array_free(addrs, TRUE), the original address objects were not freed, causing a memory leak. Fix: Always set the destructor to rspamd_inet_address_free, regardless of pool presence. The destructor will properly free address elements when the array is freed, while mempool destructor (if pool exists) will handle freeing the array itself. --- src/libutil/addr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 3cac4de877..d97dc67df5 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -1477,7 +1477,7 @@ rspamd_parse_host_port_priority(const char *str, if (*addrs == NULL) { *addrs = g_ptr_array_new_full(1, - pool == NULL ? NULL : (GDestroyNotify) rspamd_inet_address_free); + (GDestroyNotify) rspamd_inet_address_free); if (pool != NULL) { rspamd_mempool_add_destructor(pool, -- 2.47.3