aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-08-22 13:15:21 +0100
committerRon Yorston <rmy@pobox.com>2024-08-22 13:15:21 +0100
commit13a2b505b3fd7abcb4b4516d6745df870d7aee64 (patch)
treebbb0187aae3b885401917ce8fd5bbc55d2fffb82
parent4b7b4a960bab5b3e331e130b257fe8280fd9da43 (diff)
downloadbusybox-w32-13a2b505b3fd7abcb4b4516d6745df870d7aee64.tar.gz
busybox-w32-13a2b505b3fd7abcb4b4516d6745df870d7aee64.tar.bz2
busybox-w32-13a2b505b3fd7abcb4b4516d6745df870d7aee64.zip
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)
-rw-r--r--miscutils/make.c15
1 files 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)
462 /*(*cphead)->c_next = NULL; - xzalloc did it */ 462 /*(*cphead)->c_next = NULL; - xzalloc did it */
463 (*cphead)->c_cmd = xstrdup(str); 463 (*cphead)->c_cmd = xstrdup(str);
464 /*(*cphead)->c_refcnt = 0; */ 464 /*(*cphead)->c_refcnt = 0; */
465 (*cphead)->c_makefile = makefile; 465 if (makefile)
466 (*cphead)->c_makefile = xstrdup(makefile);
466 (*cphead)->c_dispno = dispno; 467 (*cphead)->c_dispno = dispno;
467} 468}
468 469
469static void 470static void
470freecmds(struct cmd *cp) 471freecmds(struct cmd *cp)
471{ 472{
472 if (cp && --cp->c_refcnt <= 0) 473 struct cmd *nextcp;
473 llist_free((llist_t *)cp, free); 474
475 if (cp && --cp->c_refcnt <= 0) {
476 for (; cp; cp = nextcp) {
477 nextcp = cp->c_next;
478 free(cp->c_cmd);
479 free((void *)cp->c_makefile);
480 free(cp);
481 }
482 }
474} 483}
475 484
476static struct name * 485static struct name *