From 17f23e8d1ef3832663c019e2420307c7068a5543 Mon Sep 17 00:00:00 2001 From: Lennox Ho Date: Mon, 18 Sep 2023 06:37:58 +0800 Subject: [PATCH] Add the ability to disable TCMalloc replacement on Windows via environment variable TCMALLOC_DISABLE_REPLACEMENT=1 --- src/windows/patch_functions.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/windows/patch_functions.cc b/src/windows/patch_functions.cc index 7bd8b33..86c4683 100644 --- a/src/windows/patch_functions.cc +++ b/src/windows/patch_functions.cc @@ -92,6 +92,7 @@ #include #include #include "base/spinlock.h" +#include "getenv_safe.h" // for TCMallocGetenvSafe #include "gperftools/malloc_hook.h" #include "malloc_hook-inl.h" #include "preamble_patcher.h" @@ -993,9 +994,16 @@ BOOL WINAPI WindowsInfo::Perftools_FreeLibrary(HMODULE hLibModule) { // --------------------------------------------------------------------- void PatchWindowsFunctions() { - // This does the libc patching in every module, and the main executable. - PatchAllModules(); - main_executable_windows.Patch(); + const char* disable_env = TCMallocGetenvSafe("TCMALLOC_DISABLE_REPLACEMENT"); + const bool should_skip = disable_env && + disable_env[0] == '1' && + disable_env[1] == '\0'; + + if (!should_skip) { + // This does the libc patching in every module, and the main executable. + PatchAllModules(); + main_executable_windows.Patch(); + } } #if 0