Skip to content

Commit 739002d

Browse files
Keelan10cscarpitta
authored andcommitted
bgpd: Free temp memory
This commit addresses a memory leak issue in the BGP Flowspec NLRI parsing function. Previously when processing NLRI, dynamically allocated memory to `temp` was not being freed, leading to a memory leak. The commit introduces the necessary code (XFREE) to properly free the temp memory after processing Flowspec NLRI. The ASan leak log for reference: ``` ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689:Direct leak of 56 byte(s) in 2 object(s) allocated from: ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- #0 0x7fc9872b5037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- #1 0x7fc986e5b1ee in qcalloc lib/memory.c:105 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#2 0x560421351bfe in bgp_nlri_parse_flowspec bgpd/bgp_flowspec.c:155 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#3 0x56042107d01c in bgp_nlri_parse bgpd/bgp_packet.c:350 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#4 0x560421086cf3 in bgp_update_receive bgpd/bgp_packet.c:2023 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#5 0x56042108deed in bgp_process_packet bgpd/bgp_packet.c:2933 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#6 0x7fc986f35bf7 in event_call lib/event.c:1995 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#7 0x7fc986e1e99d in frr_run lib/libfrr.c:1185 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#8 0x560420f3f59d in main bgpd/bgp_main.c:505 ./bgp_flowspec.test_bgp_flowspec_topo/r1.bgpd.asan.687689- FRRouting#9 0x7fc986805d09 in __libc_start_main ../csu/libc-start.c:308 ``` Signed-off-by: Keelan Cannoo <[email protected]>
1 parent 50704ea commit 739002d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bgpd/bgp_flowspec.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,16 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
189189
zlog_info("%s", local_string);
190190
}
191191
/* Process the route. */
192-
if (!withdraw)
192+
if (!withdraw) {
193193
bgp_update(peer, &p, 0, attr, afi, safi,
194194
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL,
195195
NULL, 0, 0, NULL);
196-
else
196+
} else {
197197
bgp_withdraw(peer, &p, 0, afi, safi, ZEBRA_ROUTE_BGP,
198198
BGP_ROUTE_NORMAL, NULL, NULL, 0, NULL);
199+
}
200+
201+
XFREE(MTYPE_TMP, temp);
199202
}
200203
return BGP_NLRI_PARSE_OK;
201204
}

0 commit comments

Comments
 (0)