From 13a2b505b3fd7abcb4b4516d6745df870d7aee64 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 22 Aug 2024 13:15:21 +0100 Subject: make: duplicate makefile name recorded with command Commit f3f72ac1d (make: show location of errors during build) stored a pointer to the name of the makefile with each command, for use in diagnostic messages. While this is fine for makefiles defined on the command line, the names of included files will have been freed before they can be used. Always take a copy of the makefile name stored with commands. Adds 32-48 bytes. (GitHub issue #449) --- miscutils/make.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 8c74d7113..871c434f8 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -462,15 +462,24 @@ newcmd(struct cmd **cphead, char *str) /*(*cphead)->c_next = NULL; - xzalloc did it */ (*cphead)->c_cmd = xstrdup(str); /*(*cphead)->c_refcnt = 0; */ - (*cphead)->c_makefile = makefile; + if (makefile) + (*cphead)->c_makefile = xstrdup(makefile); (*cphead)->c_dispno = dispno; } static void freecmds(struct cmd *cp) { - if (cp && --cp->c_refcnt <= 0) - llist_free((llist_t *)cp, free); + struct cmd *nextcp; + + if (cp && --cp->c_refcnt <= 0) { + for (; cp; cp = nextcp) { + nextcp = cp->c_next; + free(cp->c_cmd); + free((void *)cp->c_makefile); + free(cp); + } + } } static struct name * -- cgit v1.2.3-55-g6feb