summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2004-03-19 10:30:16 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2004-03-19 10:30:16 +0000
commit4700fd56f6db1ac60a4bef5eb9c8a0b7451a19d7 (patch)
tree7ca48f753212c062a447f8881e2ef9886c88a9ec /usr.sbin/bgpd
parentc3f893f8a1ec35869abe2c97763bf897d67f79d0 (diff)
Fix memory leak in error path. Found by Patrick Latifi. OK henning@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/rde_update.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/usr.sbin/bgpd/rde_update.c b/usr.sbin/bgpd/rde_update.c
index 07087600991..5a87d52c915 100644
--- a/usr.sbin/bgpd/rde_update.c
+++ b/usr.sbin/bgpd/rde_update.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_update.c,v 1.14 2004/03/11 17:12:51 claudio Exp $ */
+/* $OpenBSD: rde_update.c,v 1.15 2004/03/19 10:30:15 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -148,6 +148,10 @@ up_add(struct rde_peer *peer, struct update_prefix *p, struct update_attr *a)
TAILQ_INIT(&a->prefix_h);
if (RB_INSERT(uptree_attr, &peer->up_attrs, a) != NULL) {
log_warnx("uptree_attr insert failed");
+ /* cleanup */
+ free(a->attr);
+ free(a);
+ free(p);
return (-1);
}
TAILQ_INSERT_TAIL(&peer->updates, a, attr_l);
@@ -169,6 +173,12 @@ up_add(struct rde_peer *peer, struct update_prefix *p, struct update_attr *a)
/* 2.1 if not found -> add */
if (RB_INSERT(uptree_prefix, &peer->up_prefix, p) != NULL) {
log_warnx("uptree_prefix insert failed");
+ /*
+ * cleanup. But do not free a because it is already
+ * linked or NULL. up_dump_attrnlri() will remove and
+ * free the empty attribute later.
+ */
+ free(p);
return (-1);
}
peer->up_pcnt++;
@@ -282,7 +292,7 @@ up_generate_updates(struct rde_peer *peer,
p->prefix = old->prefix->prefix;
p->prefixlen = old->prefix->prefixlen;
if (up_add(peer, p, NULL) == -1)
- log_warnx("queuing update failed.");
+ log_warnx("queuing withdraw failed.");
} else {
if (peer == new->aspath->peer) {
/* Do not send routes back to sender */
@@ -365,8 +375,12 @@ up_generate_updates(struct rde_peer *peer,
fatal("up_queue_update");
if (up_generate_attr(peer, a, &attrs,
- new->aspath->nexthop) == -1)
+ new->aspath->nexthop) == -1) {
log_warnx("generation of bgp path attributes failed");
+ free(a);
+ free(p);
+ return;
+ }
/*
* use aspath_hash as attr_hash, this may be unoptimal