From 814a1d9415f5a007603e5f6fd660d6d5b2f02013 Mon Sep 17 00:00:00 2001 From: matteo Date: Thu, 20 Sep 2007 22:35:24 +0000 Subject: Fix some improper handling of malloc failures PR: bin/83344 , kern/81987 Reviewed by: alfred Approved by: re (kensmith) MFC after: 1 week --- lib/libc/rpc/getnetpath.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/libc/rpc/getnetpath.c') diff --git a/lib/libc/rpc/getnetpath.c b/lib/libc/rpc/getnetpath.c index a0a4bfd..0563544 100644 --- a/lib/libc/rpc/getnetpath.c +++ b/lib/libc/rpc/getnetpath.c @@ -101,7 +101,7 @@ setnetpath() if ((np_sessionp->nc_handlep = setnetconfig()) == NULL) { free(np_sessionp); syslog (LOG_ERR, "rpc: failed to open " NETCONFIG); - return (NULL); + goto failed; } np_sessionp->valid = NP_VALID; np_sessionp->ncp_list = NULL; @@ -110,15 +110,18 @@ setnetpath() } else { (void) endnetconfig(np_sessionp->nc_handlep);/* won't need nc session*/ np_sessionp->nc_handlep = NULL; - if ((np_sessionp->netpath = malloc(strlen(npp)+1)) == NULL) { - free(np_sessionp); - return (NULL); - } else { + if ((np_sessionp->netpath = malloc(strlen(npp)+1)) == NULL) + goto failed; + else { (void) strcpy(np_sessionp->netpath, npp); } } np_sessionp->netpath_start = np_sessionp->netpath; return ((void *)np_sessionp); + +failed: + free(np_sessionp); + return (NULL); } /* -- cgit v1.1