Module Name:    src
Committed By:   rillig
Date:           Sun Nov  8 02:05:34 UTC 2020

Modified Files:
        src/usr.bin/make: main.c

Log Message:
make(1): fix unrealistic memory leak in Main_ParseArgLine

It's unlikely that anyone ever defines an environment variable named
".MAKE" and then runs make with the -e option, which would make the
environment variable stronger than the built-in global variable.


To generate a diff of this commit:
cvs rdiff -u -r1.441 -r1.442 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.441 src/usr.bin/make/main.c:1.442
--- src/usr.bin/make/main.c:1.441	Sun Nov  8 01:56:54 2020
+++ src/usr.bin/make/main.c	Sun Nov  8 02:05:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.441 2020/11/08 01:56:54 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.442 2020/11/08 02:05:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.441 2020/11/08 01:56:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.442 2020/11/08 02:05:34 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -663,19 +663,21 @@ void
 Main_ParseArgLine(const char *line)
 {
 	Words words;
-	void *p1;
-	const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
 	char *buf;
 
 	if (line == NULL)
 		return;
 	for (; *line == ' '; ++line)
 		continue;
-	if (!*line)
+	if (line[0] == '\0')
 		return;
 
-	buf = str_concat3(argv0, " ", line);
-	free(p1);
+	{
+		void *freeIt;
+		const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &freeIt);
+		buf = str_concat3(argv0, " ", line);
+		free(freeIt);
+	}
 
 	words = Str_Words(buf, TRUE);
 	if (words.words == NULL) {

Reply via email to