ensure that heap checker initialization actually calls malloc

I.e. all recent compilers (both gcc and clang) optimize out delete(new
int) sequence to nothing. We call to tc_new and tc_delete directly to
suppress this optimization.
This commit is contained in:
Aliaksey Kandratsenka 2023-06-21 10:39:31 -04:00
parent b96dc99dbf
commit 1c3f0dda1b
1 changed files with 6 additions and 1 deletions

View File

@ -66,7 +66,12 @@ class HeapLeakCheckerGlobalPrePost {
// MallocHook_InitAtFirstAllocation_HeapLeakChecker. See malloc_hook.cc.
// This is done in this roundabout fashion in order to avoid self-deadlock
// if we directly called HeapLeakChecker_BeforeConstructors here.
delete new int;
//
// We use explicit global operator new/delete functions since
// plain 'naked' delete new int modern compilers optimize out to
// nothing. And apparently calling those global new/delete
// functions is assumed by compilers to be 'for effect' as well.
(operator delete)((operator new)(4));
// This needs to be called before the first allocation of an STL
// object, but after libc is done setting up threads (because it
// calls setenv, which requires a thread-aware errno). By