NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/51578: Close memory leak in getnetconfig.c



>Number:         51578
>Category:       lib
>Synopsis:       Close memory leak in getnetconfig.c
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 26 11:50:00 +0000 2016
>Originator:     henning petersen
>Release:        NetBSD-current
>Organization:
>Environment:
>Description:
Close memory leak, with use of tmp2.
>How-To-Repeat:

>Fix:
diff -u -u -p -r1.22 getnetconfig.c
--- lib/libc/rpc/getnetconfig.c	18 Sep 2014 13:58:20 -0000	1.22
+++ lib/libc/rpc/getnetconfig.c	16 Oct 2016 06:49:30 -0000
@@ -648,7 +648,7 @@ static struct netconfig *
 dup_ncp(struct netconfig *ncp)
 {
 	struct netconfig	*p;
-	char	*tmp;
+	char	*tmp, *tmp2;
 	u_int	i;
 
 	_DIAGASSERT(ncp != NULL);
@@ -659,6 +659,7 @@ dup_ncp(struct netconfig *ncp)
 		free(tmp);
 		return(NULL);
 	}
+	tmp2 = tmp;
 	/*
 	 * First we dup all the data from matched netconfig buffer.  Then we
 	 * adjust some of the member pointer to a pre-allocated buffer where
@@ -680,6 +681,7 @@ dup_ncp(struct netconfig *ncp)
 	if (p->nc_lookups == NULL) {
 		free(p->nc_netid);
 		free(p);
+		free(tmp2);
 		return(NULL);
 	}
 	for (i=0; i < p->nc_nlookups; i++) {



Home | Main Index | Thread Index | Old Index