Module Name: src
Committed By: rillig
Date: Mon Nov 2 18:24:42 UTC 2020
Modified Files:
src/usr.bin/make: arch.c
Log Message:
make(1): use freeIt pattern in Arch_ParseArchive
This makes the memory management more obvious than before, where the
status of the variable libName depended on subLibName.
To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/make/arch.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/arch.c
diff -u src/usr.bin/make/arch.c:1.151 src/usr.bin/make/arch.c:1.152
--- src/usr.bin/make/arch.c:1.151 Sat Oct 31 18:41:07 2020
+++ src/usr.bin/make/arch.c Mon Nov 2 18:24:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.151 2020/10/31 18:41:07 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.152 2020/11/02 18:24:42 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.151 2020/10/31 18:41:07 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.152 2020/11/02 18:24:42 rillig Exp $");
#ifdef TARGET_MACHINE
#undef MAKE_MACHINE
@@ -205,6 +205,7 @@ Arch_ParseArchive(char **linePtr, GNodeL
char *cp; /* Pointer into line */
GNode *gn; /* New node */
char *libName; /* Library-part of specification */
+ char *libName_freeIt = NULL;
char *memName; /* Member-part of specification */
char saveChar; /* Ending delimiter of member-name */
Boolean subLibName; /* TRUE if libName should have/had
@@ -225,6 +226,7 @@ Arch_ParseArchive(char **linePtr, GNodeL
const char *result;
Boolean isError;
+ /* XXX: is expanded twice: once here and once below */
(void)Var_Parse(&nested_p, ctxt, VARE_UNDEFERR|VARE_WANTRES,
&result, &result_freeIt);
/* TODO: handle errors */
@@ -243,6 +245,7 @@ Arch_ParseArchive(char **linePtr, GNodeL
if (subLibName) {
(void)Var_Subst(libName, ctxt, VARE_UNDEFERR|VARE_WANTRES, &libName);
/* TODO: handle errors */
+ libName_freeIt = libName;
}
@@ -388,12 +391,7 @@ Arch_ParseArchive(char **linePtr, GNodeL
*cp = saveChar;
}
- /*
- * If substituted libName, free it now, since we need it no longer.
- */
- if (subLibName) {
- free(libName);
- }
+ free(libName_freeIt);
cp++; /* skip the ')' */
/* We promised that linePtr would be set up at the next non-space. */