Module Name: src Committed By: christos Date: Tue Jun 7 03:04:45 UTC 2016
Modified Files: src/usr.bin/make: main.c Log Message: fix memory leak, simplify To generate a diff of this commit: cvs rdiff -u -r1.247 -r1.248 src/usr.bin/make/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.247 src/usr.bin/make/main.c:1.248 --- src/usr.bin/make/main.c:1.247 Sat Jun 4 21:39:17 2016 +++ src/usr.bin/make/main.c Mon Jun 6 23:04:45 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.247 2016/06/05 01:39:17 christos Exp $ */ +/* $NetBSD: main.c,v 1.248 2016/06/07 03:04:45 christos Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.247 2016/06/05 01:39:17 christos Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.248 2016/06/07 03:04:45 christos Exp $"; #else #include <sys/cdefs.h> #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.247 2016/06/05 01:39:17 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.248 2016/06/07 03:04:45 christos Exp $"); #endif #endif /* not lint */ #endif @@ -1869,23 +1869,15 @@ cached_realpath(const char *pathname, ch #endif } - rp = Var_Value(pathname, cache, &cp); - if (rp) { + if ((rp = Var_Value(pathname, cache, &cp)) != NULL) { /* a hit */ - if (resolved) { -#if defined(MAKE_NATIVE) || defined(HAVE_STRLCPY) - strlcpy(resolved, rp, MAXPATHLEN); -#else - strncpy(resolved, rp, MAXPATHLEN); - resolved[MAXPATHLEN - 1] = '\0'; -#endif - } else - resolved = bmake_strdup(rp); - } else { - if ((rp = realpath(pathname, resolved))) { - Var_Set(pathname, rp, cache, 0); - } - } + strncpy(resolved, rp, MAXPATHLEN); + resolved[MAXPATHLEN - 1] = '\0'; + } else if ((rp = realpath(pathname, resolved)) != NULL) { + Var_Set(pathname, rp, cache, 0); + } /* else should we negative-cache? */ + + free(cp); return rp ? resolved : NULL; }