Module Name: src Committed By: rillig Date: Sun Dec 12 13:43:47 UTC 2021
Modified Files: src/usr.bin/make: str.h Log Message: make: fix memory leak in LazyBuf This affects many operations on variable expressions. Those using LazyBuf_Done are affected, those using LazyBuf_DoneGet aren't. $ cat <<'EOF' > lazybuf-memleak.mk .for i in ${:U:range=5} . for j in ${:U:range=1000} . for k in ${:U:range=1000} . if 0 && ${VAR:Dpattern\: that needs unescaping} . endif . endfor . endfor .endfor all: @ps -o vsz -p ${.MAKE.PID} | sed 1d EOF Before using LazyBuf for the modifier ':D': $ make-2021.04.14.16.12.26 -r -f lazybuf-memleak.mk VSZ RSZ 1357136 1336432 Using LazyBuf for the modifier ':D': $ make-2021.04.14.16.59.34 -r -f lazybuf-memleak.mk VSZ RSZ 1590864 1574164 This commit alone allocates around 150 MB more data, which matches 5_000_000 strings * 30 bytes/string. It looks very wrong that the above simple makefile uses 1.3 GB of RAM at all, and it had already done this in 2017, long before LazyBuf was introduced. Before 2017.01.30.02.46.20, the above test makefile reports way smaller numbers, but that's because the modifier ':range' did not exist back then. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/str.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.