summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_aspath.c
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2023-03-15 12:31:58 +0100
committerDonatas Abraitis <donatas@opensourcerouting.org>2023-03-15 12:34:56 +0100
commit100f2249d39db1e7cd357aa648205188a67ea5a3 (patch)
tree38d0bd16a09d8b5be44c133a0352335c7a66f2d1 /bgpd/bgp_aspath.c
parentbgpd: Unlock dest if we return earlier for aggregate install (diff)
downloadfrr-100f2249d39db1e7cd357aa648205188a67ea5a3.tar.xz
frr-100f2249d39db1e7cd357aa648205188a67ea5a3.zip
bgpd: Free previously dup'ed aspath attribute for aggregate routes
Fixes memory leak: ``` ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233:Direct leak of 80 byte(s) in 2 object(s) allocated f rom: ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 0 0x7fcce641b037 in __interceptor_calloc ../../ ../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 1 0x7fcce601f874 in qcalloc lib/memory.c:105 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 2 0x55a9594c805e in aspath_dup bgpd/bgp_aspath.c:688 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 3 0x55a9594cf55b in bgp_aggr_aspath_prepare bgpd/bgp_aspath.c:2164 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 4 0x7fcce5fbc95a in hash_iterate lib/hash.c:252 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 5 0x55a9594cf82f in bgp_compute_aggregate_aspath_val bgpd/bgp_aspath.c:2223 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 6 0x55a9594cf5db in bgp_compute_aggregate_aspath bgpd/bgp_aspath.c:2179 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 7 0x55a9592740fb in bgp_add_route_to_aggregate bgpd/bgp_route.c:8035 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 8 0x55a9592750ec in bgp_aggregate_increment bgpd/bgp_route.c:8234 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 9 0x55a959263174 in bgp_update bgpd/bgp_route.c:4797 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 10 0x55a9592696c9 in bgp_nlri_parse_ip bgpd/bgp_route.c:6070 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 11 0x55a959210649 in bgp_nlri_parse bgpd/bgp_packet.c:339 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 12 0x55a95921a3a1 in bgp_update_receive bgpd/bgp_packet.c:2023 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 13 0x55a95922159b in bgp_process_packet bgpd/bgp_packet.c:2933 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 14 0x7fcce60eaa50 in thread_call lib/thread.c:1991 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 15 0x7fcce5fe2e54 in frr_run lib/libfrr.c:1185 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 16 0x55a9590d256d in main bgpd/bgp_main.c:505 ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to '')
-rw-r--r--bgpd/bgp_aspath.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index 2cc7e4657..55be70c3f 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -2157,11 +2157,15 @@ static void bgp_aggr_aspath_prepare(struct hash_bucket *hb, void *arg)
{
struct aspath *hb_aspath = hb->data;
struct aspath **aggr_aspath = arg;
+ struct aspath *aspath = NULL;
- if (*aggr_aspath)
- *aggr_aspath = aspath_aggregate(*aggr_aspath, hb_aspath);
- else
+ if (*aggr_aspath) {
+ aspath = aspath_aggregate(*aggr_aspath, hb_aspath);
+ aspath_free(*aggr_aspath);
+ *aggr_aspath = aspath;
+ } else {
*aggr_aspath = aspath_dup(hb_aspath);
+ }
}
void bgp_aggr_aspath_remove(void *arg)