]> git.ozlabs.org Git - ccan/commitdiff
failtest: plug memory leak.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 24 Aug 2011 03:22:28 +0000 (12:52 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 24 Aug 2011 03:22:28 +0000 (12:52 +0930)
Valgrind notes that our child processes leak memory.

ccan/failtest/failtest.c

index 91420dc699b9c7fdf7f40171b1e39d5fbb7d7ef3..ce4e2ceed7bac188a0ef82d79eab1c326b7805c7 100644 (file)
@@ -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)
 {
 /* 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];
                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;
        }
 
                return true;
        }