[bgpd] fix some leaks introduced in aspath rewrite.

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.
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index 9ff1205..a6b77bb 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -209,11 +209,14 @@
 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 @@
   /* 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 @@
   
   /* 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++;