From d9b14b9da1a3e0fc55286390aa2ab2490d7eee3d Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Wed, 21 Jun 2023 10:38:03 -0400 Subject: [PATCH] actually test malloc/free from InitLateMaybeRecursive This days compilers ~always optimize out free(malloc(N)) to nothing. --- src/static_vars.cc | 6 ------ src/thread_cache.cc | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/static_vars.cc b/src/static_vars.cc index fef6ed1..9689b71 100644 --- a/src/static_vars.cc +++ b/src/static_vars.cc @@ -141,12 +141,6 @@ void Static::InitLateMaybeRecursive() { CentralCacheUnlockAll, // parent calls after fork CentralCacheUnlockAll); // child calls after fork #endif - -#ifndef NDEBUG - // pthread_atfork above may malloc sometimes. Lets ensure we test - // that malloc works from here. - free(malloc(1)); -#endif } } // namespace tcmalloc diff --git a/src/thread_cache.cc b/src/thread_cache.cc index 21d0f8e..0145206 100644 --- a/src/thread_cache.cc +++ b/src/thread_cache.cc @@ -299,6 +299,12 @@ void ThreadCache::InitModule() { // We do "late" part of initialization without holding lock since // there is chance it'll recurse into malloc Static::InitLateMaybeRecursive(); + +#ifndef NDEBUG + // pthread_atfork above may malloc sometimes. Lets ensure we test + // that malloc works from here. + (operator delete)((operator new)(1)); +#endif } void ThreadCache::InitTSD() {