Blame SOURCES/memcached-restart-corrupted.patch

51bd1a
commit fa40655b49cc73194acc0e2410930f3e9a8322a7
51bd1a
Author: dormando <dormando@rydia.net>
51bd1a
Date:   Thu Mar 26 11:59:22 2020 -0700
51bd1a
51bd1a
    restart: fix corrupted restart in some scenarios
51bd1a
    
51bd1a
    If the mmap file is reused but the memory isn't supposed to be reused,
51bd1a
    pages are thrown into the global page pool. Normally when pages are
51bd1a
    released into the pool the header of the page is zero'ed so the
51bd1a
    restart_check() code will know to place it back into the global pool.
51bd1a
    
51bd1a
    When restarting multiple times the slabs_prefill() part of the startup
51bd1a
    code was missing this zero'ing step, so the _next_ time restart happens
51bd1a
    properly restart_check() could attempt to recover that memory.
51bd1a
51bd1a
diff --git a/slabs.c b/slabs.c
51bd1a
index 56b5840..ca8a8f2 100644
51bd1a
--- a/slabs.c
51bd1a
+++ b/slabs.c
51bd1a
@@ -299,6 +299,10 @@ void slabs_prefill_global(void) {
51bd1a
     while (mem_malloced < mem_limit
51bd1a
             && (ptr = memory_allocate(len)) != NULL) {
51bd1a
         grow_slab_list(0);
51bd1a
+        // Ensure the front header is zero'd to avoid confusing restart code.
51bd1a
+        // It's probably good enough to cast it and just zero slabs_clsid, but
51bd1a
+        // this is extra paranoid.
51bd1a
+        memset(ptr, 0, sizeof(item));
51bd1a
         p->slab_list[p->slabs++] = ptr;
51bd1a
     }
51bd1a
     mem_limit_reached = true;