Module Name:    src
Committed By:   christos
Date:           Mon Mar  7 21:45:43 UTC 2016

Modified Files:
        src/usr.bin/make: main.c meta.c meta.h

Log Message:
str2Lst_Append tokenizes the string and uses it in the list so we can't
free the string afterwards. Keep a copy of it and cleanup at the end.


To generate a diff of this commit:
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/make/main.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/make/meta.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/meta.h

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/main.c
diff -u src/usr.bin/make/main.c:1.241 src/usr.bin/make/main.c:1.242
--- src/usr.bin/make/main.c:1.241	Thu Feb 18 19:11:45 2016
+++ src/usr.bin/make/main.c	Mon Mar  7 16:45:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.241 2016/02/19 00:11:45 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.242 2016/03/07 21:45:43 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.241 2016/02/19 00:11:45 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.242 2016/03/07 21:45:43 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.241 2016/02/19 00:11:45 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.242 2016/03/07 21:45:43 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1381,6 +1381,9 @@ main(int argc, char **argv)
 	if (enterFlag)
 		printf("%s: Leaving directory `%s'\n", progname, curdir);
 
+#ifdef USE_META
+	meta_finish();
+#endif
 	Suff_End();
         Targ_End();
 	Arch_End();

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.52 src/usr.bin/make/meta.c:1.53
--- src/usr.bin/make/meta.c:1.52	Sat Feb 27 11:20:06 2016
+++ src/usr.bin/make/meta.c	Mon Mar  7 16:45:43 2016
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.52 2016/02/27 16:20:06 christos Exp $ */
+/*      $NetBSD: meta.c,v 1.53 2016/03/07 21:45:43 christos Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -55,7 +55,9 @@
 
 static BuildMon Mybm;			/* for compat */
 static Lst metaBailiwick;		/* our scope of control */
+static char *metaBailiwickStr;		/* string storage for the list */
 static Lst metaIgnorePaths;		/* paths we deliberately ignore */
+static char *metaIgnorePathsStr;	/* string storage for the list */
 
 #ifndef MAKE_META_IGNORE_PATHS
 #define MAKE_META_IGNORE_PATHS ".MAKE.META.IGNORE_PATHS"
@@ -597,25 +599,23 @@ meta_mode_init(const char *make_mode)
      * We consider ourselves master of all within ${.MAKE.META.BAILIWICK}
      */
     metaBailiwick = Lst_Init(FALSE);
-    cp = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}", VAR_GLOBAL,
-		   VARF_WANTRES);
-    if (cp) {
-	str2Lst_Append(metaBailiwick, cp, NULL);
+    metaBailiwickStr = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}",
+	VAR_GLOBAL, VARF_WANTRES);
+    if (metaBailiwickStr) {
+	str2Lst_Append(metaBailiwick, metaBailiwickStr, NULL);
     }
-    free(cp);
     /*
      * We ignore any paths that start with ${.MAKE.META.IGNORE_PATHS}
      */
     metaIgnorePaths = Lst_Init(FALSE);
     Var_Append(MAKE_META_IGNORE_PATHS,
 	       "/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}", VAR_GLOBAL);
-    cp = Var_Subst(NULL,
+    metaIgnorePathsStr = Var_Subst(NULL,
 		   "${" MAKE_META_IGNORE_PATHS ":O:u:tA}", VAR_GLOBAL,
 		   VARF_WANTRES);
-    if (cp) {
-	str2Lst_Append(metaIgnorePaths, cp, NULL);
+    if (metaIgnorePathsStr) {
+	str2Lst_Append(metaIgnorePaths, metaIgnorePathsStr, NULL);
     }
-    free(cp);
 }
 
 /*
@@ -775,6 +775,15 @@ meta_job_finish(Job *job)
     }
 }
 
+void
+meta_finish(void)
+{
+    Lst_Destroy(metaBailiwick, NULL);
+    free(metaBailiwickStr);
+    Lst_Destroy(metaIgnorePaths, NULL);
+    free(metaIgnorePathsStr);
+}
+
 /*
  * Fetch a full line from fp - growing bufp if needed
  * Return length in bufp.

Index: src/usr.bin/make/meta.h
diff -u src/usr.bin/make/meta.h:1.3 src/usr.bin/make/meta.h:1.4
--- src/usr.bin/make/meta.h:1.3	Sat Mar 23 01:31:29 2013
+++ src/usr.bin/make/meta.h	Mon Mar  7 16:45:43 2016
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.h,v 1.3 2013/03/23 05:31:29 sjg Exp $ */
+/*      $NetBSD: meta.h,v 1.4 2016/03/07 21:45:43 christos Exp $ */
 
 /*
  * Things needed for 'meta' mode.
@@ -42,6 +42,7 @@ extern Boolean useMeta;
 
 struct Job;				/* not defined yet */
 void meta_init(void);
+void meta_finish(void);
 void meta_mode_init(const char *);
 void meta_job_start(struct Job *, GNode *);
 void meta_job_child(struct Job *);

Reply via email to