]> git.puffer.fish Git - mirror/frr.git/commitdiff
[bgpd] fix some leaks introduced in aspath rewrite.
authorpaul <paul>
Mon, 16 Jan 2006 11:13:27 +0000 (11:13 +0000)
committerpaul <paul>
Mon, 16 Jan 2006 11:13:27 +0000 (11:13 +0000)
2006-01-16 Paul Jakma <paul.jakma@sun.com>

* bgp_aspath.c: (assegment_append_asns) XREALLOC can return
  NULL theoretically, take care not to lose the allocated data.
  (aspath_hash_alloc) aspath_dup already set the aspath
  string - fix leak.
  (aspath_parse) aspath_hash_alloc dupes the entire aspath,
  including segments, but we forgot to free the temporary
  assegment.

bgpd/ChangeLog
bgpd/bgp_aspath.c

index da7ddc44d91bfae3006d972f6180a3c8317a7f1e..ece8c4bdb98fdb626830ad22235cf43f574a450f 100644 (file)
@@ -1,3 +1,13 @@
+2006-01-16 Paul Jakma <paul.jakma@sun.com>
+
+       * bgp_aspath.c: (assegment_append_asns) XREALLOC can return
+         NULL theoretically, take care not to lose the allocated data.
+         (aspath_hash_alloc) aspath_dup already set the aspath
+         string - fix leak.
+         (aspath_parse) aspath_hash_alloc dupes the entire aspath,
+         including segments, but we forgot to free the temporary
+         assegment.
+
 2006-01-10 Juris Kalnins <juris@mt.lv>
 
        * bgpd.h: (bgp_router_id_unset) ex-function, remove.
index 9ff1205cb2d74a80689a1ac1ca2e77281124f0c4..a6b77bbb86d40ba41effc90e842da3eb39911861 100644 (file)
@@ -209,11 +209,14 @@ assegment_prepend_asns (struct assegment *seg, as_t asnum, int num)
 static struct assegment *
 assegment_append_asns (struct assegment *seg, as_t *asnos, int num)
 {
-  seg->as = XREALLOC (MTYPE_AS_SEG_DATA, seg->as,
+  as_t *newas;
+  
+  newas = XREALLOC (MTYPE_AS_SEG_DATA, seg->as,
                      ASSEGMENT_DATA_SIZE (seg->length + num));
 
-  if (seg->as)
+  if (newas)
     {
+      seg->as = newas;
       memcpy (seg->as + seg->length, asnos, ASSEGMENT_DATA_SIZE(num));
       seg->length += num;
       return seg;
@@ -582,9 +585,6 @@ aspath_hash_alloc (void *arg)
   /* New aspath strucutre is needed. */
   aspath = aspath_dup (arg);
   
-  /* Make AS path string. */
-  aspath->str = aspath_make_str_count (aspath);
-
   /* Malformed AS path value. */
   if (! aspath->str)
     {
@@ -670,6 +670,12 @@ aspath_parse (struct stream *s, size_t length)
   
   /* If already same aspath exist then return it. */
   find = hash_get (ashash, &as, aspath_hash_alloc);
+  
+  /* aspath_hash_alloc dupes segments too. that probably could be
+   * optimised out.
+   */
+  assegment_free_all (as.segments);
+  
   if (! find)
     return NULL;
   find->refcnt++;