]> git.puffer.fish Git - matthieu/frr.git/commitdiff
quagga: quagga-memory-leaks.patch
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 01:29:17 +0000 (18:29 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 01:29:17 +0000 (18:29 -0700)
Fix up some memory leaks found by valgrind
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by:

bgpd/bgp_updgrp.c
bgpd/bgp_updgrp.h
bgpd/bgpd.c
lib/zclient.c

index edd5d1fbc9faa88407e49c7fb487b691a45ee331..e06d2d38873a34093033ff7a986bf7d518b80862 100644 (file)
@@ -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)
index 44ffff71e002244a2575742fc45ab443968bba12..6d411282273c184ee5861e0dad3aa80a75a98869 100644 (file)
@@ -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);
index b9314e63dcf022fea9cb164ee154252a731152b0..894b7c939b9f3cc0d32f4b3e13abe62c2dd9324a 100644 (file)
@@ -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.
    */
index 3248d00caa349467afef44389bf1abf8f98abadd..a848df1ec804715836dc1be77862a2ee481e1294 100644 (file)
@@ -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);
 }