From 96dd78902e2a70c2a18e51c6407fe5101aa4f771 Mon Sep 17 00:00:00 2001 From: Jun-ichiro itojun Hagino Date: Sun, 21 Sep 2003 04:06:02 +0000 Subject: plug memory leak. from kame. fgsch ok --- usr.sbin/rtadvd/if.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c index 27247e7bb27..f5f29dee94a 100644 --- a/usr.sbin/rtadvd/if.c +++ b/usr.sbin/rtadvd/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.14 2002/06/10 19:57:35 espie Exp $ */ +/* $OpenBSD: if.c,v 1.15 2003/09/21 04:06:01 itojun Exp $ */ /* $KAME: if.c,v 1.17 2001/01/21 15:27:30 itojun Exp $ */ /* @@ -90,16 +90,14 @@ if_nametosdl(char *name) size_t len; struct if_msghdr *ifm; struct sockaddr *sa, *rti_info[RTAX_MAX]; - struct sockaddr_dl *sdl = NULL, *ret_sdl; + struct sockaddr_dl *sdl = NULL, *ret_sdl = NULL; if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) - return(NULL); + return (NULL); if ((buf = malloc(len)) == NULL) - return(NULL); - if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { - free(buf); - return(NULL); - } + return (NULL); + if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) + goto end; lim = buf + len; for (next = buf; next < lim; next += ifm->ifm_msglen) { @@ -123,14 +121,17 @@ if_nametosdl(char *name) } if (next == lim) { /* search failed */ - free(buf); - return(NULL); + goto end; } if ((ret_sdl = malloc(sdl->sdl_len)) == NULL) - return(NULL); + goto end; memcpy((caddr_t)ret_sdl, (caddr_t)sdl, sdl->sdl_len); - return(ret_sdl); + return (ret_sdl); + + end: + free(buf); + return (ret_sdl); } int -- cgit v1.2.3