]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Move memory initialization check (#1591)
authorAmos Jeffries <yadij@users.noreply.github.com>
Sun, 19 Nov 2023 10:04:11 +0000 (10:04 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 20 Nov 2023 09:07:03 +0000 (09:07 +0000)
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.

src/main.cc
src/mem/forward.h
src/mem/old_api.cc
src/tests/stub_libmem.cc

index 1a78e1c205f85e4939af64cdf4ca5e031a57ed96..ca1877707ffba865dfaacf7275939f88fd01440a 100644 (file)
@@ -1260,8 +1260,6 @@ mainInitialize(void)
 
 #endif
 
-    memCheckInit();
-
 #if USE_LOADABLE_MODULES
     LoadableModulesConfigure(Config.loadable_module_names);
 #endif
index fb68173a9d493dcb990876a32d42a63f5f620679..2b65edb846dbeb48dcf7cddef1100aa656953311 100644 (file)
@@ -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 */
index 2524b016d7e43c40258eb6cc9705284a173eac72..51e3916a4e20965035178c6d93e3ecf89e3b517e 100644 (file)
@@ -421,6 +421,14 @@ memConfigure(void)
     MemPools::GetInstance().setIdleLimit(new_pool_limit);
 }
 
+static mem_type &
+operator++(mem_type &aMem)
+{
+    auto tmp = static_cast<int>(aMem);
+    aMem = static_cast<mem_type>(++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)
 {
index 5976a79e635927eb27f132a8b1c9e1c969f3d01c..ef2ac8bdbadb4ef44d13a4b68b488a9e33cb3183 100644 (file)
@@ -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;