From 5bd17d483642c849f7d674c5b346f108917a09f4 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Fri, 1 Mar 2024 19:52:20 +0000 Subject: [PATCH] [FRR debug] debug community memory leak Signed-off-by: Ying Xie --- ...0037-frr-community-memory-leak-debug.patch | 89 +++++++++++++++++++ src/sonic-frr/patch/series | 1 + 2 files changed, 90 insertions(+) create mode 100644 src/sonic-frr/patch/0037-frr-community-memory-leak-debug.patch diff --git a/src/sonic-frr/patch/0037-frr-community-memory-leak-debug.patch b/src/sonic-frr/patch/0037-frr-community-memory-leak-debug.patch new file mode 100644 index 000000000000..f43e603f6d6a --- /dev/null +++ b/src/sonic-frr/patch/0037-frr-community-memory-leak-debug.patch @@ -0,0 +1,89 @@ +diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c +index 9f6f337c8..ac4ef8cf8 100644 +--- a/bgpd/bgp_community.c ++++ b/bgpd/bgp_community.c +@@ -36,7 +36,9 @@ static struct hash *comhash; + /* Allocate a new communities value. */ + static struct community *community_new(void) + { +- return XCALLOC(MTYPE_COMMUNITY, sizeof(struct community)); ++ community *com = XCALLOC(MTYPE_COMMUNITY, sizeof(struct community)); ++ zlog_warn("=== %s: allocating community %p", __func__, com); ++ return com; + } + + /* Free communities value. */ +@@ -53,6 +55,7 @@ void community_free(struct community **com) + (*com)->json = NULL; + } + ++ zlog_warn("=== %s: freeing community %p", __func__, com); + XFREE(MTYPE_COMMUNITY, (*com)); + } + +@@ -176,6 +179,7 @@ struct community *community_uniq_sort(struct community *com) + + qsort(new->val, new->size, sizeof(uint32_t), community_compare); + ++ zlog_warn("=== %s allocate %p to replace %p", __func__, new, com); + return new; + } + +@@ -492,6 +496,7 @@ struct community *community_intern(struct community *com) + if (!find->str) + set_community_string(find, false, true); + ++ zlog_warn("=== %s incoming %p returning %p", __func__, com, find); + return find; + } + +@@ -506,11 +511,13 @@ void community_unintern(struct community **com) + if ((*com)->refcnt) + (*com)->refcnt--; + ++ zlog_warn("=== %s incoming %p refcount %u", __func__, *com, (*com)->refcnt); + /* Pull off from hash. */ + if ((*com)->refcnt == 0) { + /* Community value com must exist in hash. */ + ret = (struct community *)hash_release(comhash, *com); + assert(ret != NULL); ++ zlog_warn("=== %s hash_release %p %p", __func__, *com, ret); + + community_free(com); + } +@@ -547,6 +554,7 @@ struct community *community_dup(struct community *com) + memcpy(new->val, com->val, com->size * COMMUNITY_SIZE); + } else + new->val = NULL; ++ zlog_warn("=== %s duplicate %p to replace %p", __func__, new, com); + return new; + } + +@@ -1045,6 +1053,7 @@ void bgp_remove_community_from_aggregate(struct bgp_aggregate *aggregate, + if (aggr_community->refcnt == 0) { + ret_comm = hash_release(aggregate->community_hash, + aggr_community); ++ zlog_warn("=== %s hash_release %p %p", __func__, aggr_community, ret_comm); + community_free(&ret_comm); + + bgp_compute_aggregate_community_val(aggregate); +@@ -1073,6 +1082,7 @@ void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate *aggregate, + if (aggr_community->refcnt == 0) { + ret_comm = hash_release(aggregate->community_hash, + aggr_community); ++ zlog_warn("=== %s hash_release %p %p", __func__, aggr_community, ret_comm); + community_free(&ret_comm); + } + } +diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c +index 771e48b42..6fa418c53 100644 +--- a/bgpd/bgp_routemap.c ++++ b/bgpd/bgp_routemap.c +@@ -2352,6 +2352,7 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) + if (old && old->refcnt == 0) + community_free(&old); + ++ zlog_warn("=== %s old %p new %p", __func__, old, new); + /* will be interned by caller if required */ + bgp_attr_set_community(attr, new); + diff --git a/src/sonic-frr/patch/series b/src/sonic-frr/patch/series index 3c9c6e6acf25..ad2f14d955ec 100644 --- a/src/sonic-frr/patch/series +++ b/src/sonic-frr/patch/series @@ -33,3 +33,4 @@ cross-compile-changes.patch 0034-fpm-Use-vrf_id-for-vrf-not-tabled_id.patch 0035-fpm-ignore-route-from-default-table.patch 0036-Add-support-of-bgp-l3vni-evpn.patch +0037-frr-community-memory-leak-debug.patch