Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: free memory at the end of an initi...



details:   https://anonhg.NetBSD.org/src/rev/23f58a9a6792
branches:  trunk
changeset: 953938:23f58a9a6792
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Mar 25 16:43:51 2021 +0000

description:
lint: free memory at the end of an initialization

No functional change, just more clarity in the code.

diffstat:

 usr.bin/xlint/lint1/init.c |  26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diffs (61 lines):

diff -r 21431365b072 -r 23f58a9a6792 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Thu Mar 25 16:34:59 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Thu Mar 25 16:43:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.120 2021/03/25 16:30:23 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.121 2021/03/25 16:43:51 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.120 2021/03/25 16:30:23 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.121 2021/03/25 16:43:51 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -293,6 +293,19 @@
        return &init->initstk;
 }
 
+static void
+free_initialization(struct initialization *in)
+{
+       initstack_element *el, *next;
+
+       for (el = in->initstk; el != NULL; el = next) {
+               next = el->i_enclosing;
+               free(el);
+       }
+
+       free(in);
+}
+
 #define initerr                (*current_initerr())
 #define initsym                (*current_initsym())
 #define initstk                (*current_initstk())
@@ -449,7 +462,7 @@
 
        curr_init = init;
        init = init->next;
-       free(curr_init);
+       free_initialization(curr_init);
        debug_step("end initialization");
 }
 
@@ -535,13 +548,6 @@
        if (initerr)
                return;
 
-       /* TODO: merge into end_initialization */
-       /* free memory used in last initialization */
-       while ((istk = initstk) != NULL) {
-               initstk = istk->i_enclosing;
-               free(istk);
-       }
-
        /* TODO: merge into init_using_expr */
        while (namedmem != NULL)
                designator_shift_name();



Home | Main Index | Thread Index | Old Index