Subject: Re: usr.bin/make/var.c
To: Charles M. Hannum <root@ihack.net>
From: None <itojun@iijlab.net>
List: source-changes
Date: 03/10/2001 08:46:03
>>I'm failing to see how this change could possibly be correct.  Was it
>>even tested (with, say, a build of the source tree)?
>>As the comments indicate, VAR_KEEP is used when the value of the string
>>must be retained, because they're used by the caller.  This is the case
>>for, e.g., :U expansion.  Your change will actually cause the string to
>>be freed in that case!
>	i'll revisit it.  anyway, there's a bug around here that makes a
>	pointer into a dangling pointer.

	how's this?

itojun


Index: var.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/make/var.c,v
retrieving revision 1.57
diff -u -r1.57 var.c
--- var.c	2001/03/09 12:49:05	1.57
+++ var.c	2001/03/09 23:45:01
@@ -2575,7 +2575,8 @@
 	     */
 	    *freePtr = TRUE;
 	}
-	Buf_Destroy(v->val, destroy);
+	if (str != (char *)Buf_GetAll(v->val, (int *)NULL))
+	    Buf_Destroy(v->val, destroy);
 	free((Address)v->name);
 	free((Address)v);
     } else if (v->flags & VAR_JUNK) {
@@ -2584,7 +2585,7 @@
 	 * doesn't try to free a static pointer.
 	 * If VAR_KEEP is also set then we want to keep str as is.
 	 */
-	if ((v->flags & VAR_KEEP) != 0) {
+	if (!(v->flags & VAR_KEEP)) {
 	    if (*freePtr) {
 		free(str);
 	    }
@@ -2598,7 +2599,8 @@
 		str = var_Error;
 	    }
 	}
-	Buf_Destroy(v->val, TRUE);
+	if (str != (char *)Buf_GetAll(v->val, (int *)NULL))
+	    Buf_Destroy(v->val, TRUE);
 	free((Address)v->name);
 	free((Address)v);
     }