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 when parsing '.if ${expr}...



details:   https://anonhg.NetBSD.org/src/rev/d771c455db1d
branches:  trunk
changeset: 1027621:d771c455db1d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 13 07:06:39 2021 +0000

description:
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.

diffstat:

 usr.bin/make/cond.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (29 lines):

diff -r ec25b82232ca -r d771c455db1d usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Mon Dec 13 06:11:34 2021 +0000
+++ b/usr.bin/make/cond.c       Mon Dec 13 07:06:39 2021 +0000
@@ -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 @@
        }
 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;
 }
 



Home | Main Index | Thread Index | Old Index