bgpd: plug several memleaks

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2016-10-21 20:13:51 -02:00
parent 235022cbaa
commit 37d361e7fd
4 changed files with 22 additions and 9 deletions

View File

@ -113,6 +113,12 @@ bgp_address_hash_alloc (void *p)
return addr; return addr;
} }
static void
bgp_address_hash_free (void *addr)
{
XFREE (MTYPE_BGP_ADDR, addr);
}
static unsigned int static unsigned int
bgp_address_hash_key_make (void *p) bgp_address_hash_key_make (void *p)
{ {
@ -142,7 +148,7 @@ bgp_address_destroy (struct bgp *bgp)
{ {
if (bgp->address_hash == NULL) if (bgp->address_hash == NULL)
return; return;
hash_clean(bgp->address_hash, NULL); hash_clean(bgp->address_hash, bgp_address_hash_free);
hash_free(bgp->address_hash); hash_free(bgp->address_hash);
bgp->address_hash = NULL; bgp->address_hash = NULL;
} }

View File

@ -1792,6 +1792,7 @@ bgp_redist_del (struct bgp *bgp, afi_t afi, u_char type, u_short instance)
if (red) if (red)
{ {
listnode_delete(bgp->redist[afi][type], red); listnode_delete(bgp->redist[afi][type], red);
XFREE (MTYPE_BGP_REDIST, red);
if (!bgp->redist[afi][type]->count) if (!bgp->redist[afi][type]->count)
{ {
list_free(bgp->redist[afi][type]); list_free(bgp->redist[afi][type]);

View File

@ -1047,6 +1047,12 @@ peer_free (struct peer *peer)
peer->host = NULL; peer->host = NULL;
} }
if (peer->domainname)
{
XFREE (MTYPE_BGP_PEER_HOST, peer->domainname);
peer->domainname = NULL;
}
if (peer->ifname) if (peer->ifname)
{ {
XFREE(MTYPE_BGP_PEER_IFNAME, peer->ifname); XFREE(MTYPE_BGP_PEER_IFNAME, peer->ifname);
@ -3123,6 +3129,7 @@ bgp_delete (struct bgp *bgp)
struct peer *peer; struct peer *peer;
struct peer_group *group; struct peer_group *group;
struct listnode *node, *next; struct listnode *node, *next;
struct vrf *vrf;
afi_t afi; afi_t afi;
int i; int i;
@ -3186,8 +3193,6 @@ bgp_delete (struct bgp *bgp)
* routes to be processed still referencing the struct bgp. * routes to be processed still referencing the struct bgp.
*/ */
listnode_delete (bm->bgp, bgp); listnode_delete (bm->bgp, bgp);
if (list_isempty(bm->bgp))
bgp_close ();
/* Deregister from Zebra, if needed */ /* Deregister from Zebra, if needed */
if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) if (IS_BGP_INST_KNOWN_TO_ZEBRA(bgp))
@ -3196,6 +3201,10 @@ bgp_delete (struct bgp *bgp)
/* Free interfaces in this instance. */ /* Free interfaces in this instance. */
bgp_if_finish (bgp); bgp_if_finish (bgp);
vrf = bgp_vrf_lookup_by_instance_type (bgp);
if (vrf)
bgp_vrf_unlink (bgp, vrf);
thread_master_free_unused(bm->master); thread_master_free_unused(bm->master);
bgp_unlock(bgp); /* initial reference */ bgp_unlock(bgp); /* initial reference */
@ -3223,7 +3232,6 @@ bgp_free (struct bgp *bgp)
{ {
afi_t afi; afi_t afi;
safi_t safi; safi_t safi;
struct vrf *vrf;
list_delete (bgp->group); list_delete (bgp->group);
list_delete (bgp->peer); list_delete (bgp->peer);
@ -3245,13 +3253,9 @@ bgp_free (struct bgp *bgp)
bgp_table_finish (&bgp->rib[afi][safi]); bgp_table_finish (&bgp->rib[afi][safi]);
} }
bgp_scan_finish (bgp);
bgp_address_destroy (bgp); bgp_address_destroy (bgp);
/* If Default instance or VRF, unlink from the VRF structure. */
vrf = bgp_vrf_lookup_by_instance_type (bgp);
if (vrf)
bgp_vrf_unlink (bgp, vrf);
if (bgp->name) if (bgp->name)
XFREE(MTYPE_BGP, bgp->name); XFREE(MTYPE_BGP, bgp->name);

View File

@ -37,6 +37,7 @@
#include "bgpd/bgp_table.h" #include "bgpd/bgp_table.h"
#include "bgpd/bgp_route.h" #include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h" #include "bgpd/bgp_attr.h"
#include "bgpd/bgp_nexthop.h"
#include "bgpd/bgp_mpath.h" #include "bgpd/bgp_mpath.h"
#define VT100_RESET "\x1b[0m" #define VT100_RESET "\x1b[0m"
@ -116,6 +117,7 @@ bgp_create_fake (as_t *as, const char *name)
bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM; bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM;
} }
bgp_scan_init (bgp);
bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF; bgp->default_local_pref = BGP_DEFAULT_LOCAL_PREF;
bgp->default_holdtime = BGP_DEFAULT_HOLDTIME; bgp->default_holdtime = BGP_DEFAULT_HOLDTIME;
bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE; bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE;