+/* Free up memory, so valgrind doesn't report leaks. */
+static void free_everything(void)
+{
+ unsigned int i;
+
+ /* We don't do this in cleanup: needed even for failed opens. */
+ for (i = 0; i < history_num; i++) {
+ if (history[i].type == FAILTEST_OPEN)
+ free((char *)history[i].u.open.pathname);
+ }
+ free(history);
+}
+
+static NORETURN void failtest_cleanup(bool forced_cleanup, int status)
+{
+ int i;
+
+ /* For children, we don't care if they "failed" the testing. */
+ if (control_fd != -1)
+ status = 0;
+
+ if (forced_cleanup)
+ history_num--;
+
+ /* Cleanup everything, in reverse order. */
+ for (i = history_num - 1; i >= 0; i--) {
+ if (!history[i].cleanup)
+ continue;
+ if (!forced_cleanup) {
+ printf("Leak at %s:%u\n",
+ history[i].file, history[i].line);
+ status = 1;
+ }
+ history[i].cleanup(&history[i].u);
+ }
+
+ free_everything();
+ tell_parent(SUCCESS);
+ exit(status);
+}
+