]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
monitor: fix memleak in setelem cb
authorFlorian Westphal <fw@strlen.de>
Wed, 21 Jan 2026 13:33:21 +0000 (14:33 +0100)
committerFlorian Westphal <fw@strlen.de>
Thu, 22 Jan 2026 11:00:27 +0000 (12:00 +0100)
since 4521732ebbf3 ("monitor: missing cache and set handle initialization")
these fields are set via handle_merge(), so don't clobber those
fields in json output case:

==31877==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 16 byte(s) in 2 object(s) allocated from:
 #0 0x7f0cb9f29d4b in strdup asan/asan_interceptors.cpp:593
 #1 0x7f0cb9b584fd in xstrdup src/utils.c:80
 #2 0x7f0cb9b355b3 in handle_merge src/rule.c:127
 #3 0x7f0cb9ae12b8 in netlink_events_setelem_cb src/monitor.c:457

Seen when running tests/monitor with asan enabled.

Fixes: 4521732ebbf3 ("monitor: missing cache and set handle initialization")
Signed-off-by: Florian Westphal <fw@strlen.de>
src/monitor.c

index fafeeebe914b8b9901d584171106424a2d65f1e8..6532c9c50f8d99a1bea984bba052930af735b61b 100644 (file)
@@ -496,13 +496,7 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
                nft_mon_print(monh, "\n");
                break;
        case NFTNL_OUTPUT_JSON:
-               dummyset->handle.family = family;
-               dummyset->handle.set.name = setname;
-               dummyset->handle.table.name = table;
                monitor_print_element_json(monh, cmd, dummyset);
-               /* prevent set_free() from trying to free those */
-               dummyset->handle.set.name = NULL;
-               dummyset->handle.table.name = NULL;
                if (!nft_output_echo(&monh->ctx->nft->output))
                        nft_mon_print(monh, "\n");
                break;