Skip to contentSkip to conversation

monitor: fix memleak in setelem cb

PATCH In review Florian Westphal 2 participants 3 messages Jan 21 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 monitor: fix memleak in setelem cb

since 4521732ebbf3 ("monitor: missing cache and set handle initialization") these fields are initied via handle_merge(), so don't clear them in the json output case. Fixes:

==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.

---
 src/monitor.c | 6 ------
 1 file changed, 6 deletions(-)
src/monitor.c +0 -6
index fafeeebe914b..6532c9c50f8d 100644
@@ -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;
Signature · 1 line
2.52.0
reviewer
#1 lore raw

Hi,

Quoted 11 lines · Florian Westphal

since 4521732ebbf3 ("monitor: missing cache and set handle initialization") these fields are initied via handle_merge(), so don't clear them in the json output case. Fixes:

==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

Quoted 3 lines

Seen when running tests/monitor with asan enabled.

Looks like a fix of commit 4521732ebbf34 ("monitor: missing cache and set handle initialization")?

Cheers, Phil

author maintainer
#2 lore raw
Quoted 12 lines · Phil Sutter
Quoted 11 lines · Florian Westphal

since 4521732ebbf3 ("monitor: missing cache and set handle initialization") these fields are initied via handle_merge(), so don't clear them in the json output case. Fixes:

==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

Quoted 6 lines
Quoted 3 lines

Seen when running tests/monitor with asan enabled.

Looks like a fix of commit 4521732ebbf34 ("monitor: missing cache and set handle initialization")?

Yes