From d9aab8470193156ba0fed236fc1a1d7b4d1342ae Mon Sep 17 00:00:00 2001 From: Han Fei Date: Wed, 8 Feb 2023 16:20:42 +0100 Subject: [PATCH] fix fork hang --- src/Common/gwp_asan.h | 34 ---------------------------------- src/Common/memory.h | 4 ++++ src/Common/new_delete.cpp | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 34 deletions(-) delete mode 100644 src/Common/gwp_asan.h diff --git a/src/Common/gwp_asan.h b/src/Common/gwp_asan.h deleted file mode 100644 index 29295153875..00000000000 --- a/src/Common/gwp_asan.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "config.h" - -#include - -#if USE_GWP_ASAN -#include -#include -#endif - -namespace Memory -{ - -#if USE_GWP_ASAN -static gwp_asan::GuardedPoolAllocator GuardedAlloc; - -static struct InitGwpAsan -{ - InitGwpAsan() - { - gwp_asan::options::initOptions(); - gwp_asan::options::Options &opts = gwp_asan::options::getOptions(); - GuardedAlloc.init(opts); - } - - static bool isInit() - { - return GuardedAlloc.getAllocatorState()->GuardedPagePoolEnd != 0; - } -} init_gwp_asan; -#endif - -} diff --git a/src/Common/memory.h b/src/Common/memory.h index e166939baaf..1be2238d3c4 100644 --- a/src/Common/memory.h +++ b/src/Common/memory.h @@ -18,6 +18,10 @@ # include #endif +#if USE_GWP_ASAN +static gwp_asan::GuardedPoolAllocator GuardedAlloc; +#endif + namespace Memory { diff --git a/src/Common/new_delete.cpp b/src/Common/new_delete.cpp index 871ab750907..738e26ab08c 100644 --- a/src/Common/new_delete.cpp +++ b/src/Common/new_delete.cpp @@ -23,6 +23,25 @@ extern "C" extern void zone_register(); } +#if USE_GWP_ASAN +/// Both clickhouse_new_delete and clickhouse_common_io links gwp_asan, but It should only init once, otherwise it +/// will cause unexpected deadlock. +static struct InitGwpAsan +{ + InitGwpAsan() + { + gwp_asan::options::initOptions(); + gwp_asan::options::Options &opts = gwp_asan::options::getOptions(); + GuardedAlloc.init(opts); + } + + static bool isInit() + { + return GuardedAlloc.getAllocatorState()->GuardedPagePoolEnd != 0; + } +} init_gwp_asan; +#endif + static struct InitializeJemallocZoneAllocatorForOSX { InitializeJemallocZoneAllocatorForOSX()