Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): fix unrealistic memory leak in Main_Pa...



details:   https://anonhg.NetBSD.org/src/rev/503af3b95e1d
branches:  trunk
changeset: 942429:503af3b95e1d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 08 02:05:34 2020 +0000

description:
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.

diffstat:

 usr.bin/make/main.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (45 lines):

diff -r 308d597e8e7b -r 503af3b95e1d usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sun Nov 08 01:56:54 2020 +0000
+++ b/usr.bin/make/main.c       Sun Nov 08 02:05:34 2020 +0000
@@ -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 @@
 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) {



Home | Main Index | Thread Index | Old Index