Blame SOURCES/memcached-restart-corrupted.patch

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