From 330cec3de07108b6fcf3d47358a2471d68a0881b Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 9 Oct 2018 20:16:37 -0400 Subject: [PATCH 1/2] bgpd: Use a more appropriate memory type for a string Track the memory type associated with the bartian address interface a bit better, instead of using MTYPE_TMP. Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index ce7f5b40f5..4f246fdd11 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -47,6 +47,8 @@ #include "zebra/rib.h" #include "zebra/zserv.h" /* For ZEBRA_SERV_PATH. */ +DEFINE_MTYPE_STATIC(BGPD, MARTIAN_STRING, "BGP Martian Address Intf String"); + char *bnc_str(struct bgp_nexthop_cache *bnc, char *buf, int size) { prefix2str(&(bnc->node->p), buf, size); @@ -205,7 +207,7 @@ static void bgp_address_hash_string_del(void *val) { char *data = val; - XFREE(MTYPE_TMP, data); + XFREE(MTYPE_MARTIAN_STRING, data); } static void *bgp_address_hash_alloc(void *p) @@ -278,7 +280,7 @@ static void bgp_address_add(struct bgp *bgp, struct connected *ifc, break; } if (!node) { - name = XSTRDUP(MTYPE_TMP, ifc->ifp->name); + name = XSTRDUP(MTYPE_MARTIAN_STRING, ifc->ifp->name); listnode_add(addr->ifp_name_list, name); } } From b91299153d809c9243add21cf637d6aa24c36fc2 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 9 Oct 2018 20:19:01 -0400 Subject: [PATCH 2/2] bgpd: Cleanup memory leak with the martian address intf string When cleaning up a interface string, from the linked list we were dropping the name pointer which held the allocated martian address intf string. Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 4f246fdd11..45c596254f 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -305,8 +305,10 @@ static void bgp_address_del(struct bgp *bgp, struct connected *ifc, break; } - if (node) + if (node) { list_delete_node(addr->ifp_name_list, node); + XFREE(MTYPE_MARTIAN_STRING, name); + } if (addr->ifp_name_list->count == 0) { hash_release(bgp->address_hash, addr);