Skip to content

Truly independent web browser

LibTest: Ignore leaks from the expression of a death test

Luke Wilde3609473c12b4
diff --git a/Libraries/LibTest/AssertionHandler.cpp b/Libraries/LibTest/AssertionHandler.cpp
index 7aec7c00a2d..515fe6209d0 100644
--- a/Libraries/LibTest/AssertionHandler.cpp
+++ b/Libraries/LibTest/AssertionHandler.cpp
@@ -6,6 +6,10 @@
#include <LibTest/Macros.h>
+#ifdef HAS_LEAK_SANITIZER
+# include <sanitizer/lsan_interface.h>
+#endif
+
namespace Test {
static libtest_jmp_buf g_assert_jmp_buf = {};
@@ -16,7 +20,17 @@ libtest_jmp_buf& assertion_jump_buffer() { return g_assert_jmp_buf; }
void set_assertion_jump_validity(bool validity)
{
+ if (validity == g_assert_jmp_buf_valid)
+ return;
g_assert_jmp_buf_valid = validity;
+
+ // Allocations made while a death test's expression runs are not reported as leaks.
+#ifdef HAS_LEAK_SANITIZER
+ if (validity)
+ __lsan_disable();
+ else
+ __lsan_enable();
+#endif
}
static bool is_assertion_jump_valid()