NetBSD Problem Report #51578

From www@NetBSD.org  Wed Oct 26 11:46:24 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 035D67A26C
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 26 Oct 2016 11:46:24 +0000 (UTC)
Message-Id: <20161026114622.BBF417A2BE@mollari.NetBSD.org>
Date: Wed, 26 Oct 2016 11:46:22 +0000 (UTC)
From: henning-petersen@t-online.de
Reply-To: henning-petersen@t-online.de
To: gnats-bugs@NetBSD.org
Subject: Close memory leak in getnetconfig.c
X-Send-Pr-Version: www-1.0

>Number:         51578
>Category:       lib
>Synopsis:       Close memory leak in getnetconfig.c
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 26 11:50:00 +0000 2016
>Closed-Date:    Mon Oct 31 05:17:53 +0000 2016
>Last-Modified:  Mon Oct 31 05:17:53 +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++) {

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51578 CVS commit: src/lib/libc/rpc
Date: Wed, 26 Oct 2016 11:39:30 -0400

 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.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 31 Oct 2016 05:17:53 +0000
State-Changed-Why:
committed, thanks


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.