Module Name:    src
Committed By:   christos
Date:           Wed Oct 26 15:39:30 UTC 2016

Modified Files:
        src/lib/libc/rpc: getnetconfig.c

Log Message:
PR/51578: Henning Petersen: Fix leak on error.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/rpc/getnetconfig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/rpc/getnetconfig.c
diff -u src/lib/libc/rpc/getnetconfig.c:1.23 src/lib/libc/rpc/getnetconfig.c:1.24
--- src/lib/libc/rpc/getnetconfig.c:1.23	Wed Oct 26 11:36:17 2016
+++ src/lib/libc/rpc/getnetconfig.c	Wed Oct 26 11:39:30 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetconfig.c,v 1.23 2016/10/26 15:36:17 christos Exp $	*/
+/*	$NetBSD: getnetconfig.c,v 1.24 2016/10/26 15:39:30 christos Exp $	*/
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -36,7 +36,7 @@
 #if 0
 static        char sccsid[] = "@(#)getnetconfig.c	1.12 91/12/19 SMI";
 #else
-__RCSID("$NetBSD: getnetconfig.c,v 1.23 2016/10/26 15:36:17 christos Exp $");
+__RCSID("$NetBSD: getnetconfig.c,v 1.24 2016/10/26 15:39:30 christos Exp $");
 #endif
 #endif
 
@@ -649,12 +649,12 @@ static struct netconfig *
 dup_ncp(struct netconfig *ncp)
 {
 	struct netconfig	*p;
-	char	*tmp;
+	char	*tmp, *tmp2;
 	u_int	i;
 
 	_DIAGASSERT(ncp != NULL);
 
-	if ((tmp = malloc(MAXNETCONFIGLINE)) == NULL)
+	if ((tmp2 = tmp = malloc(MAXNETCONFIGLINE)) == NULL)
 		return NULL;
 	if ((p = malloc(sizeof(*p))) == NULL) {
 		free(tmp);
@@ -679,6 +679,7 @@ dup_ncp(struct netconfig *ncp)
 	p->nc_device = strcpy(tmp, ncp->nc_device);
 	p->nc_lookups = calloc((size_t)(p->nc_nlookups + 1), sizeof(char *));
 	if (p->nc_lookups == NULL) {
+		free(tmp2);
 		free(p->nc_netid);
 		free(p);
 		return NULL;

Reply via email to