Module Name:    src
Committed By:   rillig
Date:           Sat May 25 08:03:19 UTC 2024

Modified Files:
        src/usr.bin/make: dir.c job.c parse.c suff.c var.c

Log Message:
make: fix some more memory leaks


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 src/usr.bin/make/dir.c
cvs rdiff -u -r1.471 -r1.472 src/usr.bin/make/job.c
cvs rdiff -u -r1.724 -r1.725 src/usr.bin/make/parse.c
cvs rdiff -u -r1.378 -r1.379 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1111 -r1.1112 src/usr.bin/make/var.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/dir.c
diff -u src/usr.bin/make/dir.c:1.292 src/usr.bin/make/dir.c:1.293
--- src/usr.bin/make/dir.c:1.292	Sat May 25 00:00:25 2024
+++ src/usr.bin/make/dir.c	Sat May 25 08:03:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.292 2024/05/25 00:00:25 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -132,7 +132,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.292 2024/05/25 00:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.293 2024/05/25 08:03:19 rillig Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -876,6 +876,7 @@ SearchPath_ExpandMiddle(SearchPath *path
 	(void)SearchPath_Add(partPath, dirpath);
 	DirExpandPath(wildcardComponent + 1, partPath, expansions);
 	SearchPath_Free(partPath);
+	free(dirpath);
 }
 
 /*

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.471 src/usr.bin/make/job.c:1.472
--- src/usr.bin/make/job.c:1.471	Tue May  7 18:26:22 2024
+++ src/usr.bin/make/job.c	Sat May 25 08:03:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.471 2024/05/07 18:26:22 sjg Exp $	*/
+/*	$NetBSD: job.c,v 1.472 2024/05/25 08:03:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -141,7 +141,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.471 2024/05/07 18:26:22 sjg Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.472 2024/05/25 08:03:19 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -2482,6 +2482,7 @@ Job_ParseShell(char *line)
 			}
 		}
 	} else {
+		free(UNCONST(shellPath));
 		shellPath = path;
 		shellName = newShell.name != NULL ? newShell.name
 		    : str_basename(path);

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.724 src/usr.bin/make/parse.c:1.725
--- src/usr.bin/make/parse.c:1.724	Sat May 25 00:00:25 2024
+++ src/usr.bin/make/parse.c	Sat May 25 08:03:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.724 2024/05/25 00:00:25 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.725 2024/05/25 08:03:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.724 2024/05/25 00:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.725 2024/05/25 08:03:19 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -2303,9 +2303,15 @@ ParseEOF(void)
 
 	Cond_EndFile();
 
-	if (curFile->guardState == GS_DONE)
-		HashTable_Set(&guards, curFile->name.str, curFile->guard);
-	else if (curFile->guard != NULL) {
+	if (curFile->guardState == GS_DONE) {
+		HashEntry *he = HashTable_CreateEntry(&guards,
+		    curFile->name.str, NULL);
+		if (he->value != NULL) {
+			free(((Guard *)he->value)->name);
+			free(he->value);
+		}
+		HashEntry_Set(he, curFile->guard);
+	} else if (curFile->guard != NULL) {
 		free(curFile->guard->name);
 		free(curFile->guard);
 	}

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.378 src/usr.bin/make/suff.c:1.379
--- src/usr.bin/make/suff.c:1.378	Wed Feb  7 06:43:02 2024
+++ src/usr.bin/make/suff.c	Sat May 25 08:03:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.378 2024/02/07 06:43:02 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.379 2024/05/25 08:03:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
 #include "dir.h"
 
 /*	"@(#)suff.c	8.4 (Berkeley) 3/21/94"	*/
-MAKE_RCSID("$NetBSD: suff.c,v 1.378 2024/02/07 06:43:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.379 2024/05/25 08:03:19 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -1223,6 +1223,7 @@ ExpandWildcards(GNodeListNode *cln, GNod
 
 		DEBUG1(SUFF, "%s...", name);
 		gn = Targ_GetNode(name);
+		free(name);
 
 		/* Insert gn before the original child. */
 		Lst_InsertBefore(&pgn->children, cln, gn);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1111 src/usr.bin/make/var.c:1.1112
--- src/usr.bin/make/var.c:1.1111	Sat May 25 00:00:25 2024
+++ src/usr.bin/make/var.c	Sat May 25 08:03:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1111 2024/05/25 00:00:25 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1112 2024/05/25 08:03:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -132,7 +132,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1111 2024/05/25 00:00:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1112 2024/05/25 08:03:19 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2396,11 +2396,11 @@ ApplyModifier_Loop(const char **pp, ModC
 		    "In the :@ modifier, the variable name \"%s\" "
 		    "must not contain a dollar",
 		    args.var);
-		return AMR_CLEANUP;
+		goto cleanup_tvar;
 	}
 
 	if (!ParseModifierPart(pp, '@', VARE_PARSE_BALANCED, ch, &strBuf))
-		return AMR_CLEANUP;
+		goto cleanup_tvar;
 	str = LazyBuf_DoneGet(&strBuf);
 	args.body = str.str;
 
@@ -2419,6 +2419,10 @@ done:
 	FStr_Done(&tvar);
 	FStr_Done(&str);
 	return AMR_OK;
+
+cleanup_tvar:
+	FStr_Done(&tvar);
+	return AMR_CLEANUP;
 }
 
 static void

Reply via email to