diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2004-03-11 18:56:35 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2004-03-11 18:56:35 +0000 |
commit | d11a78cb1ef0a59a6990036fd548bc29d5f1cafe (patch) | |
tree | 4c61337964ea8e1e995338c10cc1f5081840bfad /usr.sbin/bgpctl/bgpctl.c | |
parent | fe36baf3bd08d66ecd39cf20d7ab7997d99d81ba (diff) |
Plugging memory leaks is OK but don't break intended behaviour. So this time
do it correctly.
Diffstat (limited to 'usr.sbin/bgpctl/bgpctl.c')
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index cd4c33a939f..522eb6b338e 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.47 2004/03/11 16:39:34 claudio Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.48 2004/03/11 18:56:34 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -688,17 +688,17 @@ show_rib_summary_msg(struct imsg *imsg) struct ctl_show_rib_prefix *p; u_char *asdata; - if (rib != NULL) { - free(rib); - rib = NULL; - } - if (aspath != NULL) { - free(aspath); - aspath = NULL; - } - switch (imsg->hdr.type) { case IMSG_CTL_SHOW_RIB: + if (rib != NULL) { + free(rib); + rib = NULL; + } + if (aspath != NULL) { + free(aspath); + aspath = NULL; + } + if ((rib = malloc(imsg->hdr.len - IMSG_HEADER_SIZE)) == NULL) err(1, NULL); memcpy(rib, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE); @@ -734,9 +734,26 @@ show_rib_summary_msg(struct imsg *imsg) printf("%s\n", print_origin(rib->origin, 1)); break; case IMSG_CTL_END: + if (rib != NULL) { + free(rib); + rib = NULL; + } + if (aspath != NULL) { + free(aspath); + aspath = NULL; + } + return (1); - break; default: + if (rib != NULL) { + free(rib); + rib = NULL; + } + if (aspath != NULL) { + free(aspath); + aspath = NULL; + } + break; } |