summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-06-19 17:39:36 +0000
committerjmallett <jmallett@FreeBSD.org>2002-06-19 17:39:36 +0000
commitf27248e5ba91fe3e6b2dbd676475ecb826ee7b24 (patch)
tree3540a33bf89c6436b99faa73770d7c2c0ecadcf9 /usr.bin/make
parentb07b8a3f99a0a0a3fe76233557247871500315fc (diff)
downloadFreeBSD-src-f27248e5ba91fe3e6b2dbd676475ecb826ee7b24.zip
FreeBSD-src-f27248e5ba91fe3e6b2dbd676475ecb826ee7b24.tar.gz
Fix a memory leak from previous commit by freeing the possibly expanded
string at the first opportunity, being sure to now always allocate the new string from VarPossiblyExpand. Oops.
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/var.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index f7e5e47..6a472a2 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -217,10 +217,10 @@ VarCmp (v, name)
* Expand a variable name's embedded variables in the given context.
*
* Results:
- * The string pointed to by `name' may change.
+ * The contents of name, possibly expanded.
*
* Side Effects:
- * None.
+ * The caller must free the new contents or old contents of name.
*-----------------------------------------------------------------------
*/
static void
@@ -230,6 +230,8 @@ VarPossiblyExpand(name, ctxt)
{
if (strchr(*name, '$') != NULL)
*name = Var_Subst(NULL, *name, ctxt, 0);
+ else
+ *name = estrdup(*name);
}
/*-
@@ -512,6 +514,7 @@ Var_Set (name, val, ctxt)
if (ctxt == VAR_CMD) {
setenv(name, val, 1);
}
+ free(name);
}
/*-
@@ -569,6 +572,7 @@ Var_Append (name, val, ctxt)
Lst_AtFront(ctxt->context, (void *)v);
}
}
+ free(name);
}
/*-
@@ -593,6 +597,7 @@ Var_Exists(name, ctxt)
VarPossiblyExpand(&name, ctxt);
v = VarFind(name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV);
+ free(name);
if (v == (Var *)NULL) {
return(FALSE);
@@ -626,6 +631,7 @@ Var_Value (name, ctxt, frp)
VarPossiblyExpand(&name, ctxt);
v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
+ free(name);
*frp = NULL;
if (v != (Var *) NULL) {
char *p = ((char *)Buf_GetAll(v->val, (int *)NULL));
OpenPOWER on IntegriCloud