[Top][All Lists]

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

[PATCH] Fix memory leak of prereqs created for second expansion

From: Mike Haboustak
Subject: [PATCH] Fix memory leak of prereqs created for second expansion
Date: Thu, 11 Jul 2019 18:57:53 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

When second expansion is enabled, the record_files function allocates a
struct dep for each dependency string that requires expansion. Later, the
expand_deps function completes the expansion, parses new prereqs, and
frees the dependency string, but it does not free the dependency struct.
This results in one leaked struct dep per-rule that requires second

Sample repro makefile is attached. The leaked memory can be tracked
using valgrind.

 src/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/file.c b/src/file.c
index c20fcf8..1f9270b 100644
--- a/src/file.c
+++ b/src/file.c
@@ -634,8 +634,11 @@ expand_deps (struct file *f)

-      /* Add newly parsed prerequisites.  */
+      /* free the original prereq */
       next = d->next;
+      free (d);
+      /* Add newly parsed prerequisites.  */
       *dp = new;
       for (dp = &new->next, d = new->next; d != 0; dp = &d->next, d = d->next)

Attachment: se_leak.mk
Description: Text document

reply via email to

[Prev in Thread] Current Thread [Next in Thread]