From 05ab011adecfe0ceb82f854a805138f4d235f15c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 24 Aug 2011 12:52:28 +0930 Subject: [PATCH] failtest: plug memory leak. Valgrind notes that our child processes leak memory. --- ccan/failtest/failtest.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c index 91420dc6..ce4e2cee 100644 --- a/ccan/failtest/failtest.c +++ b/ccan/failtest/failtest.c @@ -310,6 +310,16 @@ static void restore_files(struct saved_file *s) } } +static void free_files(struct saved_file *s) +{ + while (s) { + struct saved_file *next = s->next; + free(s->contents); + free(s); + s = next; + } +} + /* Free up memory, so valgrind doesn't report leaks. */ static void free_everything(void) { @@ -475,6 +485,8 @@ static bool should_fail(struct failtest_call *call) if (output[1] != STDOUT_FILENO && output[1] != STDERR_FILENO) close(output[1]); control_fd = control[1]; + /* Valgrind spots the leak if we don't free these. */ + free_files(files); return true; } -- 2.39.2