Module Name: src Committed By: rillig Date: Sat Aug 1 07:03:50 UTC 2020
Modified Files: src/usr.bin/make: var.c Log Message: make(1): clearly mark a variable in Var_Set_with_flags for freeing No functional change. To generate a diff of this commit: cvs rdiff -u -r1.369 -r1.370 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/var.c diff -u src/usr.bin/make/var.c:1.369 src/usr.bin/make/var.c:1.370 --- src/usr.bin/make/var.c:1.369 Sat Aug 1 06:35:00 2020 +++ src/usr.bin/make/var.c Sat Aug 1 07:03:50 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.369 2020/08/01 06:35:00 rillig Exp $ */ +/* $NetBSD: var.c,v 1.370 2020/08/01 07:03:50 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.369 2020/08/01 06:35:00 rillig Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.370 2020/08/01 07:03:50 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.369 2020/08/01 06:35:00 rillig Exp $"); +__RCSID("$NetBSD: var.c,v 1.370 2020/08/01 07:03:50 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -782,7 +782,7 @@ Var_Set_with_flags(const char *name, con VarSet_Flags flags) { Var *v; - char *expanded_name = NULL; + char *name_freeIt = NULL; /* * We only look for a variable in the given context since anything set @@ -790,17 +790,17 @@ Var_Set_with_flags(const char *name, con * point in searching them all just to save a bit of memory... */ if (strchr(name, '$') != NULL) { - expanded_name = Var_Subst(name, ctxt, VARE_WANTRES); - if (expanded_name[0] == '\0') { + const char *unexpanded_name = name; + name = name_freeIt = Var_Subst(name, ctxt, VARE_WANTRES); + if (name[0] == '\0') { if (DEBUG(VAR)) { fprintf(debug_file, "Var_Set(\"%s\", \"%s\", ...) " "name expands to empty string - ignored\n", - name, val); + unexpanded_name, val); } - free(expanded_name); + free(name_freeIt); return; } - name = expanded_name; } if (ctxt == VAR_GLOBAL) { v = VarFind(name, VAR_CMD, 0); @@ -863,7 +863,7 @@ Var_Set_with_flags(const char *name, con save_dollars = s2Boolean(val, save_dollars); out: - free(expanded_name); + free(name_freeIt); if (v != NULL) VarFreeEnv(v, TRUE); }