From 19b613f30bc55b25331d2f2f7ac8519250560b40 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Mon, 26 Apr 2010 08:46:32 +0000 Subject: Fix some memory leaks on config reload failure and move one particular cleanup loop to parse.y where it belongs. OK henning@ --- usr.sbin/bgpd/bgpd.c | 6 +----- usr.sbin/bgpd/parse.y | 11 ++++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 346c8443f4f..f6227c98f7a 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.158 2010/04/22 08:24:58 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.159 2010/04/26 08:46:31 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -434,10 +434,6 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_head *mrt_l, if (parse_config(conffile, conf, mrt_l, peer_l, &net_l, &rules_l)) { log_warnx("config file %s has errors, not reloading", conffile); - while ((rr = SIMPLEQ_FIRST(&ribnames))) { - SIMPLEQ_REMOVE_HEAD(&ribnames, entry); - free(rr); - } return (1); } diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 0731a460a4e..1d9c7ee23c0 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.250 2010/03/31 18:53:23 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.251 2010/04/26 08:46:31 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -2335,6 +2335,7 @@ parse_config(char *filename, struct bgpd_config *xconf, struct listen_addr *la; struct network *n; struct filter_rule *r; + struct rde_rib *rr; int errors = 0; if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL) @@ -2411,23 +2412,31 @@ parse_config(char *filename, struct bgpd_config *xconf, while ((n = TAILQ_FIRST(netconf)) != NULL) { TAILQ_REMOVE(netconf, n, entry); + filterset_free(&n->net.attrset); free(n); } while ((r = TAILQ_FIRST(filter_l)) != NULL) { TAILQ_REMOVE(filter_l, r, entry); + filterset_free(&r->set); free(r); } while ((r = TAILQ_FIRST(peerfilter_l)) != NULL) { TAILQ_REMOVE(peerfilter_l, r, entry); + filterset_free(&r->set); free(r); } while ((r = TAILQ_FIRST(groupfilter_l)) != NULL) { TAILQ_REMOVE(groupfilter_l, r, entry); + filterset_free(&r->set); free(r); } + while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { + SIMPLEQ_REMOVE_HEAD(&ribnames, entry); + free(rr); + } } else { errors += merge_config(xconf, conf, peer_l, listen_addrs); errors += mrt_mergeconfig(xmconf, mrtconf); -- cgit v1.2.3