Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: fix memory leak in wildcard targets and s...



details:   https://anonhg.NetBSD.org/src/rev/db01014912cc
branches:  trunk
changeset: 366743:db01014912cc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 11 17:58:15 2022 +0000

description:
make: fix memory leak in wildcard targets and sources

$ cat <<'EOF' > glob-leak.mk
all:
        @pid=$$$$; \
        ppid=$$(ps -o ppid -p "$$pid" | sed 1d); \
        ps -o vsz,rsz -p $$ppid | sed 1d

.for _ in ${:U:${:Urange=$n}}
bin/*: source
.endfor
EOF

$ make.before -r -f glob-leak.mk n=1
19424 5280
$ make.before -r -f glob-leak.mk n=10
24220 10208
$ make.before -r -f glob-leak.mk n=100
71280 58504
$ make.before -r -f glob-leak.mk n=1000
556356 541620

$ make.after -r -f glob-leak.mk n=1
19208 5040
$ make.after -r -f glob-leak.mk n=10
22132 8092
$ make.after -r -f glob-leak.mk n=100
49040 35940
$ make.after -r -f glob-leak.mk n=1000
324160 314400

That's a saving of 40% already.  The remaining 60% are suspicious as
well since after the first iteration of the .for loop, make's internal
state doesn't change conceptually, so there's no need to throw more
memory at it.

diffstat:

 usr.bin/make/parse.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r a47c3932abbb -r db01014912cc usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Jun 11 17:41:35 2022 +0000
+++ b/usr.bin/make/parse.c      Sat Jun 11 17:58:15 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.678 2022/06/11 17:41:35 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.679 2022/06/11 17:58:15 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.678 2022/06/11 17:41:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.679 2022/06/11 17:58:15 rillig Exp $");
 
 /*
  * A file being read.
@@ -1045,7 +1045,7 @@
                while (!Lst_IsEmpty(&targetNames)) {
                        char *targName = Lst_Dequeue(&targetNames);
                        HandleSingleDependencyTargetMundane(targName);
-                       /* TODO: free targName */
+                       free(targName);
                }
        } else
                HandleSingleDependencyTargetMundane(targetName);



Home | Main Index | Thread Index | Old Index