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 memory leak in Var_Delete (since y...



details:   https://anonhg.NetBSD.org/src/rev/680f829acd36
branches:  trunk
changeset: 979246:680f829acd36
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Dec 20 15:04:29 2020 +0000

description:
make(1): fix memory leak in Var_Delete (since yesterday)

The memory leak had been introduced in var.c 1.736 from 2020-12-19
20:47:24.

diffstat:

 usr.bin/make/var.c |  19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diffs (43 lines):

diff -r 7ba4042e9fa4 -r 680f829acd36 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Dec 20 14:52:16 2020 +0000
+++ b/usr.bin/make/var.c        Sun Dec 20 15:04:29 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.745 2020/12/20 14:32:13 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.746 2020/12/20 15:04:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.745 2020/12/20 14:32:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.746 2020/12/20 15:04:29 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -498,15 +498,18 @@
 void
 Var_Delete(const char *name, GNode *ctxt)
 {
-       char *name_freeIt = NULL;
-
-       if (strchr(name, '$') != NULL) {
-               (void)Var_Subst(name, VAR_GLOBAL, VARE_WANTRES, &name_freeIt);
+       FStr varname = FStr_InitRefer(name);
+
+       if (strchr(varname.str, '$') != NULL) {
+               char *expanded;
+               (void)Var_Subst(varname.str, VAR_GLOBAL, VARE_WANTRES,
+                   &expanded);
                /* TODO: handle errors */
-               name = name_freeIt;
+               varname = FStr_InitOwn(expanded);
        }
 
-       Var_DeleteVar(name, ctxt);
+       Var_DeleteVar(varname.str, ctxt);
+       FStr_Done(&varname);
 }
 
 /*



Home | Main Index | Thread Index | Old Index