Module Name: src Committed By: rillig Date: Mon Dec 13 07:06:39 UTC 2021
Modified Files: src/usr.bin/make: cond.c Log Message: make: fix memory leak when parsing '.if ${expr}' (since 2004-04-13) $ ( echo 'VAR=value' perl -e 'printf(".if \${VAR}\n.endif\n" x 5000);'; echo 'all:' printf '\t%s\n' \ '@pid=$$$$; \' \ 'ppid=$$(ps -o ppid -p "$$pid" | sed 1d); \' \ 'ps -o vsz,rsz -p $$ppid | sed 1d' ) > leak-cond2.mk $ make-2004.04.08.07.24.26 -r -f leak-cond.mk 2668 $ make-2004.04.13.16.06.23 -r -f leak-cond.mk 3964 $ echo $(((3964 - 2668) * 1000 / 5000)) 259 This 259 is close enough to the 256 from Buf_Init in CondParser_Leaf. To generate a diff of this commit: cvs rdiff -u -r1.302 -r1.303 src/usr.bin/make/cond.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/cond.c diff -u src/usr.bin/make/cond.c:1.302 src/usr.bin/make/cond.c:1.303 --- src/usr.bin/make/cond.c:1.302 Sun Dec 12 09:36:00 2021 +++ src/usr.bin/make/cond.c Mon Dec 13 07:06:39 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.302 2021/12/12 09:36:00 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.303 2021/12/13 07:06:39 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -95,7 +95,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.302 2021/12/12 09:36:00 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.303 2021/12/13 07:06:39 rillig Exp $"); /* * The parsing of conditional expressions is based on this grammar: @@ -523,8 +523,9 @@ CondParser_Leaf(CondParser *par, bool do } got_str: str = FStr_InitOwn(buf.data); + buf.data = NULL; cleanup: - Buf_DoneData(&buf); /* XXX: memory leak on failure? */ + Buf_Done(&buf); *out_str = str; }