From 30ea95f57dba3607bdf80a4dbec0462eac63b41d Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Mon, 17 Apr 2000 23:45:25 +0000 Subject: Don't free Makefile filenames when the file is finished reading, but keep them for error reporting. --- usr.bin/make/extern.h | 3 ++- usr.bin/make/parse.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h index c0f3ecee080..6ac0af8c4fd 100644 --- a/usr.bin/make/extern.h +++ b/usr.bin/make/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.19 2000/02/02 13:47:47 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.20 2000/04/17 23:45:23 espie Exp $ */ /* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */ /*- @@ -98,6 +98,7 @@ void Parse_End __P((void)); void Parse_FromString __P((char *, unsigned long)); Lst Parse_MainName __P((void)); unsigned long Parse_Getlineno __P((void)); +const char *Parse_Getfilename __P((void)); /* str.c */ void str_init __P((void)); diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index a2d99608c97..309f20b43cc 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.37 2000/03/26 16:21:32 espie Exp $ */ +/* $OpenBSD: parse.c,v 1.38 2000/04/17 23:45:24 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: parse.c,v 1.37 2000/03/26 16:21:32 espie Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.38 2000/04/17 23:45:24 espie Exp $"; #endif #endif /* not lint */ @@ -104,6 +104,10 @@ static char rcsid[] = "$OpenBSD: parse.c,v 1.37 2000/03/26 16:21:32 espie Exp $" #include "buf.h" #include "pathnames.h" +#ifdef CLEANUP +static Lst fileNames; /* file names to free at end */ +#endif + /* * These values are returned by ParseEOF to tell Parse_File whether to * CONTINUE parsing, i.e. it had only reached the end of an include file, @@ -1808,6 +1812,9 @@ ParseDoInclude (file) * place. Naturally enough, we start reading at line number 0. */ fname = fullname; +#ifdef CLEANUP + Lst_AtEnd(fileNames, fname); +#endif lineno = 0; curFILE = fopen (fullname, "r"); @@ -1857,7 +1864,6 @@ Parse_FromString(str, newlineno) curPTR = (PTR *) emalloc (sizeof (PTR)); curPTR->str = curPTR->ptr = str; lineno = newlineno; - fname = estrdup(fname); } @@ -1991,6 +1997,9 @@ ParseTraditionalInclude (file) * place. Naturally enough, we start reading at line number 0. */ fname = fullname; +#ifdef CLEANUP + lst_AtEnd(fileNames, fname); +#endif lineno = 0; curFILE = fopen (fullname, "r"); @@ -2028,7 +2037,6 @@ ParseEOF (opened) if ((ifile = (IFile *)Lst_DeQueue(includes)) == NULL) return DONE; - free ((Address) fname); fname = ifile->fname; lineno = ifile->lineno; if (opened && curFILE) @@ -2455,7 +2463,10 @@ Parse_File(name, stream) *line; /* the line we're working on */ inLine = FALSE; - fname = name; + fname = estrdup(name); +#ifdef CLEANUP + Lst_AtEnd(fileNames, fname); +#endif curFILE = stream; lineno = 0; fatals = 0; @@ -2641,6 +2652,7 @@ Parse_Init () includes = Lst_Init(); #ifdef CLEANUP targCmds = Lst_Init(); + fileNames = Lst_Init(); #endif } @@ -2649,6 +2661,7 @@ Parse_End() { #ifdef CLEANUP Lst_Destroy(targCmds, (void (*) __P((ClientData))) free); + Lst_Destroy(fileNames, (void (*) __P((ClientData))) free); if (targets) Lst_Destroy(targets, NOFREE); Lst_Destroy(sysIncPath, Dir_Destroy); @@ -2697,3 +2710,9 @@ Parse_Getlineno() return lineno; } +const char * +Parse_Getfilename() +{ + return fname; +} + -- cgit v1.2.3