]> git.ozlabs.org Git - ccan/blobdiff - ccan/failtest/failtest.c
failtest: use 64 bit offsets if available.
[ccan] / ccan / failtest / failtest.c
index 91420dc699b9c7fdf7f40171b1e39d5fbb7d7ef3..224898f9cb75ad8ad782c0dc983ade12c544cc06 100644 (file)
@@ -1,5 +1,5 @@
 /* Licensed under LGPL - see LICENSE file for details */
-#include "config.h"
+#include <ccan/failtest/failtest.h>
 #include <stdarg.h>
 #include <string.h>
 #include <stdio.h>
@@ -17,7 +17,6 @@
 #include <assert.h>
 #include <ccan/read_write_all/read_write_all.h>
 #include <ccan/failtest/failtest_proto.h>
-#include <ccan/failtest/failtest.h>
 #include <ccan/build_assert/build_assert.h>
 
 enum failtest_result (*failtest_hook)(struct failtest_call *, unsigned);
@@ -310,6 +309,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 +484,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;
        }