diff options
author | 2004-03-11 18:56:34 +0000 | |
---|---|---|
committer | 2004-03-11 18:56:34 +0000 | |
commit | 848a1a34b6af51180bfbaf928fc24d61a2d72da5 (patch) | |
tree | 03d49a1098bdf111c2f4583cd4d73ceb8f4ca71d | |
parent | repair pkg_add -, by making sure `-' is a special object. (diff) | |
download | wireguard-openbsd-848a1a34b6af51180bfbaf928fc24d61a2d72da5.tar.xz wireguard-openbsd-848a1a34b6af51180bfbaf928fc24d61a2d72da5.zip |
Plugging memory leaks is OK but don't break intended behaviour. So this time
do it correctly.
-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; } |