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 evaluating ${.SUFFIX...



details:   https://anonhg.NetBSD.org/src/rev/1778142411e8
branches:  trunk
changeset: 1027602:1778142411e8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 13 01:00:10 2021 +0000

description:
make: fix memory leak when evaluating ${.SUFFIXES} (since yesterday)

perl -e '
    printf(".SUFFIXES: %s\n", "x" x 224);
    printf("_:=\${.SUFFIXES}\n" x 100_000);
    printf("all:\n");
' \
| MALLOC_CONF=stats_print:true \
    ./make -r -f - 2>&1 \
| awk '/bins:/,/^ *256/ { print $1 "\t" $4}'

Roughly 100000 less allocations for bin size 16, for the variable name.

diffstat:

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

diffs (28 lines):

diff -r 87048041505f -r 1778142411e8 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Dec 13 00:33:33 2021 +0000
+++ b/usr.bin/make/var.c        Mon Dec 13 01:00:10 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.974 2021/12/13 00:33:33 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.975 2021/12/13 01:00:10 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.974 2021/12/13 00:33:33 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.975 2021/12/13 01:00:10 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -4407,7 +4407,8 @@
 
        if (v == NULL && Substring_Equals(name, ".SUFFIXES")) {
                char *suffixes = Suff_NamesStr();
-               v = VarNew(Substring_Str(name), suffixes, false, true);
+               v = VarNew(FStr_InitRefer(".SUFFIXES"), suffixes,
+                   false, true);
                free(suffixes);
        } else if (v == NULL)
                v = FindLocalLegacyVar(name, scope, out_true_extraModifiers);



Home | Main Index | Thread Index | Old Index