From 3d68677ef17266ddcc54483498398ffcff42e2aa Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 19 May 2015 18:29:17 -0700 Subject: [PATCH] quagga: quagga-memory-leaks.patch Fix up some memory leaks found by valgrind Signed-off-by: Donald Sharp Reviewed-by: --- bgpd/bgp_updgrp.c | 18 ++++++++++++++++-- bgpd/bgp_updgrp.h | 4 +++- bgpd/bgpd.c | 5 +++-- lib/zclient.c | 6 ++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index edd5d1fbc9..e06d2d3887 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -144,7 +144,7 @@ conf_copy (struct peer *dst, struct peer *src, afi_t afi, safi_t safi) dst->v_routeadv = src->v_routeadv; dst->flags = src->flags; dst->af_flags[afi][safi] = src->af_flags[afi][safi]; - dst->host = strdup (src->host); + dst->host = XSTRDUP (MTYPE_BGP_PEER_HOST, src->host); dst->cap = src->cap; dst->af_cap[afi][safi] = src->af_cap[afi][safi]; dst->afc_nego[afi][safi] = src->afc_nego[afi][safi]; @@ -727,6 +727,8 @@ update_group_delete (struct update_group *updgrp) hash_release (updgrp->bgp->update_groups[updgrp->afid], updgrp); conf_release (updgrp->conf, updgrp->afi, updgrp->safi); + + XFREE (MTYPE_BGP_PEER_HOST, updgrp->conf->host); XFREE (MTYPE_BGP_PEER, updgrp->conf); XFREE (MTYPE_BGP_UPDGRP, updgrp); } @@ -1550,7 +1552,7 @@ update_subgroup_split_peer (struct peer_af *paf, struct update_group *updgrp) } void -update_group_init (struct bgp *bgp) +update_bgp_group_init (struct bgp *bgp) { int afid; @@ -1559,6 +1561,18 @@ update_group_init (struct bgp *bgp) updgrp_hash_cmp); } +void +update_bgp_group_free (struct bgp *bgp) +{ + int afid; + + AF_FOREACH (afid) + { + hash_free(bgp->update_groups[afid]); + bgp->update_groups[afid] = NULL; + } +} + void update_group_show (struct bgp *bgp, afi_t afi, safi_t safi, struct vty *vty, u_int64_t subgrp_id) diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index 44ffff71e0..6d41128227 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -353,7 +353,9 @@ struct updwalk_context /* Prototypes. */ /* bgp_updgrp.c */ -extern void update_group_init (struct bgp *); +extern void update_bgp_group_init (struct bgp *); +extern void udpate_bgp_group_free (struct bgp *); + extern void update_group_show (struct bgp *bgp, afi_t afi, safi_t safi, struct vty *vty, u_int64_t subgrp_id); extern void update_group_show_stats (struct bgp *bgp, struct vty *vty); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index b9314e63dc..894b7c939b 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -2546,7 +2546,7 @@ bgp_create (as_t *as, const char *name) THREAD_TIMER_ON (master, bgp->t_startup, bgp_startup_timer_expire, bgp, bgp->restart_time); - update_group_init(bgp); + update_bgp_group_init(bgp); return bgp; } @@ -2728,7 +2728,8 @@ bgp_delete (struct bgp *bgp) BGP_TIMER_OFF(bgp->t_rmap_def_originate_eval); bgp_unlock(bgp); } - + + update_bgp_group_free (bgp); /* Remove visibility via the master list - there may however still be * routes to be processed still referencing the struct bgp. */ diff --git a/lib/zclient.c b/lib/zclient.c index 3248d00caa..a848df1ec8 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -165,7 +165,13 @@ zclient_stop (struct zclient *zclient) void zclient_reset (struct zclient *zclient) { + int afi; + zclient_stop (zclient); + + for (afi = AFI_IP; afi < AFI_MAX; afi++) + redist_del_instance (&zclient->redist[afi][zclient->redist_default], zclient->instance); + zclient_init (zclient, zclient->redist_default, zclient->instance); } -- 2.39.5