Module Name:    src
Committed By:   rillig
Date:           Sat Feb 26 11:57:21 UTC 2022

Modified Files:
        src/usr.bin/make: lst.c

Log Message:
make: fix memory leak in Lst_Remove (since 2020-10-23)

The code to free the list node (as opposed to the node data) was
accidentally removed in lst.c 1.83 from 2020-10-23 as part of cleaning
up an unnecessarily complicated function for traversing linked lists.

The memory leak only affected a few lists that actually used Lst_Remove.
Most lists are append-only and are freed using Lst_Done or Lst_Free at
the end, which correctly free the memory.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/usr.bin/make/lst.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/lst.c
diff -u src/usr.bin/make/lst.c:1.105 src/usr.bin/make/lst.c:1.106
--- src/usr.bin/make/lst.c:1.105	Mon Mar 15 16:45:30 2021
+++ src/usr.bin/make/lst.c	Sat Feb 26 11:57:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.105 2021/03/15 16:45:30 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.106 2022/02/26 11:57:21 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.105 2021/03/15 16:45:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.106 2022/02/26 11:57:21 rillig Exp $");
 
 static ListNode *
 LstNodeNew(ListNode *prev, ListNode *next, void *datum)
@@ -163,6 +163,8 @@ Lst_Remove(List *list, ListNode *ln)
 		list->first = ln->next;
 	if (list->last == ln)
 		list->last = ln->prev;
+
+	free(ln);
 }
 
 /* Replace the datum in the given node with the new datum. */

Reply via email to