From: Amos Jeffries Date: Sun, 19 Nov 2023 10:04:11 +0000 (+0000) Subject: Move memory initialization check (#1591) X-Git-Tag: SQUID_7_0_1~280 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a54550f8e9a839cb7288a9f05d2adace8b9e477;p=thirdparty%2Fsquid.git Move memory initialization check (#1591) mainInitialize() is far too late to be validating that memory pools created with memDataInit() have been correctly initialized. They will have already been used by debugging, and many other components early-setup logic. Instead run the check at the last possible moment before declaring the memory pools to be fully initialized. --- diff --git a/src/main.cc b/src/main.cc index 1a78e1c205..ca1877707f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1260,8 +1260,6 @@ mainInitialize(void) #endif - memCheckInit(); - #if USE_LOADABLE_MODULES LoadableModulesConfigure(Config.loadable_module_names); #endif diff --git a/src/mem/forward.h b/src/mem/forward.h index fb68173a9d..2b65edb846 100644 --- a/src/mem/forward.h +++ b/src/mem/forward.h @@ -70,7 +70,6 @@ void memFreeRigid(void *, size_t net_size); FREE *memFreeBufFunc(size_t size); int memInUse(mem_type); void memDataInit(mem_type, const char *, size_t, int, bool doZero = true); -void memCheckInit(void); size_t memStringCount(); #endif /* _SQUID_SRC_MEM_FORWARD_H */ diff --git a/src/mem/old_api.cc b/src/mem/old_api.cc index 2524b016d7..51e3916a4e 100644 --- a/src/mem/old_api.cc +++ b/src/mem/old_api.cc @@ -421,6 +421,14 @@ memConfigure(void) MemPools::GetInstance().setIdleLimit(new_pool_limit); } +static mem_type & +operator++(mem_type &aMem) +{ + auto tmp = static_cast(aMem); + aMem = static_cast(++tmp); + return aMem; +} + void Mem::Init(void) { @@ -450,37 +458,19 @@ Mem::Init(void) memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0); GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024); + // Test that all entries are initialized + for (auto t = MEM_NONE; ++t < MEM_MAX;) { + // If you hit this assertion, then you forgot to add a + // memDataInit() line for type 't'. + assert(GetPool(t)); + } + MemIsInitialized = true; // finally register with the cache manager Mgr::RegisterAction("mem", "Memory Utilization", Mem::Stats, 0, 1); } -static mem_type & -operator++(mem_type &aMem) -{ - int tmp = (int)aMem; - aMem = (mem_type)(++tmp); - return aMem; -} - -/* - * Test that all entries are initialized - */ -void -memCheckInit(void) -{ - mem_type t = MEM_NONE; - - while (++t < MEM_MAX) { - /* - * If you hit this assertion, then you forgot to add a - * memDataInit() line for type 't'. - */ - assert(GetPool(t)); - } -} - void memClean(void) { diff --git a/src/tests/stub_libmem.cc b/src/tests/stub_libmem.cc index 5976a79e63..ef2ac8bdba 100644 --- a/src/tests/stub_libmem.cc +++ b/src/tests/stub_libmem.cc @@ -74,7 +74,6 @@ static void cxx_xfree(void * ptr) {xfree(ptr);} FREE *memFreeBufFunc(size_t) {return cxx_xfree;} int memInUse(mem_type) STUB_RETVAL(0) void memDataInit(mem_type, const char *, size_t, int, bool) STUB_NOP -void memCheckInit(void) STUB_NOP #include "mem/Pool.h" static MemPools tmpMemPools;