Module Name: src Committed By: rillig Date: Sun Dec 20 14:52:16 UTC 2020
Modified Files: src/usr.bin/make: parse.c Log Message: make(1): clean up memory handling in VarAssign_EvalShell To generate a diff of this commit: cvs rdiff -u -r1.506 -r1.507 src/usr.bin/make/parse.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/parse.c diff -u src/usr.bin/make/parse.c:1.506 src/usr.bin/make/parse.c:1.507 --- src/usr.bin/make/parse.c:1.506 Sun Dec 20 14:48:35 2020 +++ src/usr.bin/make/parse.c Sun Dec 20 14:52:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -117,7 +117,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $"); /* types and constants */ @@ -1962,27 +1962,27 @@ static void VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt, FStr *out_avalue) { - const char *cmd, *errfmt; + FStr cmd; + const char *errfmt; char *cmdOut; - void *cmd_freeIt = NULL; - cmd = uvalue; - if (strchr(cmd, '$') != NULL) { - char *ecmd; - (void)Var_Subst(cmd, VAR_CMDLINE, VARE_WANTRES | VARE_UNDEFERR, - &ecmd); + cmd = FStr_InitRefer(uvalue); + if (strchr(cmd.str, '$') != NULL) { + char *expanded; + (void)Var_Subst(cmd.str, VAR_CMDLINE, + VARE_WANTRES | VARE_UNDEFERR, &expanded); /* TODO: handle errors */ - cmd = cmd_freeIt = ecmd; + cmd = FStr_InitOwn(expanded); } - cmdOut = Cmd_Exec(cmd, &errfmt); + cmdOut = Cmd_Exec(cmd.str, &errfmt); Var_Set(name, cmdOut, ctxt); *out_avalue = FStr_InitOwn(cmdOut); if (errfmt != NULL) Parse_Error(PARSE_WARNING, errfmt, cmd); - free(cmd_freeIt); + FStr_Done(&cmd); } /* Perform a variable assignment.