diff --git a/AK/LsanSuppressions.h b/AK/LsanSuppressions.h index 4049f7d45424c..a4f5b53c65f54 100644 --- a/AK/LsanSuppressions.h +++ b/AK/LsanSuppressions.h @@ -8,9 +8,10 @@ #include -#ifdef HAS_ADDRESS_SANITIZER +#if defined(HAS_ADDRESS_SANITIZER) +# include + extern "C" { -char const* __lsan_default_suppressions(); char const* __lsan_default_suppressions() { // Both Skia and Chromium suppress false positive FontConfig leaks @@ -20,3 +21,14 @@ char const* __lsan_default_suppressions() } } #endif + +namespace AK { + +inline void perform_leak_sanitizer_checks() +{ +#if defined(HAS_ADDRESS_SANITIZER) + __lsan_do_leak_check(); +#endif +} + +} diff --git a/Libraries/LibMain/Main.cpp b/Libraries/LibMain/Main.cpp index 270b88e7e7ba9..15ffa97fa178e 100644 --- a/Libraries/LibMain/Main.cpp +++ b/Libraries/LibMain/Main.cpp @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include #include @@ -41,10 +43,14 @@ int main(int argc, char** argv) .argv = argv, .strings = arguments.span(), }); + + ScopeGuard guard { []() { AK::perform_leak_sanitizer_checks(); } }; + if (result.is_error()) { auto error = result.release_error(); warnln("\033[31;1mRuntime error\033[0m: {}", error); return Main::return_code_for_errors(); } + return result.value(); }