]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix memory leak in address parsing for *-any addresses
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 28 Oct 2025 15:01:21 +0000 (15:01 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 28 Oct 2025 15:01:21 +0000 (15:01 +0000)
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

index 3cac4de8778d842a1d96889aab62caa0e7ed72db..d97dc67df53f4a579de4ba10ed6c0fcbe97cf05e 100644 (file)
@@ -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,