summaryrefslogtreecommitdiff
path: root/bgpd
diff options
context:
space:
mode:
authorpaul <paul>2006-01-16 11:13:27 +0000
committerpaul <paul>2006-01-16 11:13:27 +0000
commit02335429e8cf2afc191fd518a3b55564bf6e5b2c (patch)
treeaea6397f2ff082bded4380aa1db27245ff21994c /bgpd
parentc1b9800a60f073c7d57f6232f9af7ae39bc3353a (diff)
[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.
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/ChangeLog10
-rw-r--r--bgpd/bgp_aspath.c16
2 files changed, 21 insertions, 5 deletions
diff --git a/bgpd/ChangeLog b/bgpd/ChangeLog
index da7ddc44..ece8c4bd 100644
--- a/bgpd/ChangeLog
+++ b/bgpd/ChangeLog
@@ -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.
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index 9ff1205c..a6b77bbb 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -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++;