FIXTURE_DATA(fixture_name) self; \
                pid_t child = 1; \
                int status = 0; \
-               bool jmp = false; \
+               /* Makes sure there is only one teardown, even when child forks again. */ \
+               bool *teardown = mmap(NULL, sizeof(*teardown), \
+                       PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); \
+               *teardown = false; \
                memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \
                if (setjmp(_metadata->env) == 0) { \
                        /* Use the same _metadata. */ \
                                _metadata->exit_code = KSFT_FAIL; \
                        } \
                } \
-               else \
-                       jmp = true; \
                if (child == 0) { \
-                       if (_metadata->setup_completed && !_metadata->teardown_parent && !jmp) \
+                       if (_metadata->setup_completed && !_metadata->teardown_parent && \
+                                       __sync_bool_compare_and_swap(teardown, false, true)) \
                                fixture_name##_teardown(_metadata, &self, variant->data); \
                        _exit(0); \
                } \
-               if (_metadata->setup_completed && _metadata->teardown_parent) \
+               if (_metadata->setup_completed && _metadata->teardown_parent && \
+                               __sync_bool_compare_and_swap(teardown, false, true)) \
                        fixture_name##_teardown(_metadata, &self, variant->data); \
+               munmap(teardown, sizeof(*teardown)); \
                if (!WIFEXITED(status) && WIFSIGNALED(status)) \
                        /* Forward signal to __wait_for_test(). */ \
                        kill(getpid(), WTERMSIG(status)); \