Fix build for OpenSSL 3.0.0 . Bug 2810
[exim.git] / src / src / store.c
index ad4da3c2e5faf4a794f33c7b6d2972f7be2b2745..e4cd722c31b7f1e5b293a71575fc9556bb96ab29 100644 (file)
@@ -3,7 +3,7 @@
 *************************************************/
 
 /* Copyright (c) University of Cambridge 1995 - 2018 */
-/* Copyright (c) The Exim maintainers 2019 - 2020 */
+/* Copyright (c) The Exim maintainers 2019 - 2021 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* Exim gets and frees all its store through these functions. In the original
@@ -255,14 +255,11 @@ log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Taint mismatch, %s: %s %d\n",
 void
 store_writeprotect(int pool)
 {
+#if !defined(COMPILE_UTILITY) && !defined(MISSING_POSIX_MEMALIGN)
 for (storeblock * b = chainbase[pool]; b; b = b->next)
-  {
-#ifndef COMPILE_UTILITY
   if (mprotect(b, ALIGNED_SIZEOF_STOREBLOCK + b->length, PROT_READ) != 0)
-    DEBUG(D_any) debug_printf("config block mprotect: (%d) %s\n", errno, strerror(errno))
+    DEBUG(D_any) debug_printf("config block mprotect: (%d) %s\n", errno, strerror(errno));
 #endif
-    ;
-  }
 }
 
 /******************************************************************************/
@@ -286,7 +283,7 @@ Returns:      pointer to store (panic on malloc failure)
 */
 
 void *
-store_get_3(int size, BOOL tainted, const char *func, int linenumber)
+store_get_3(int size, BOOL tainted, const char * func, int linenumber)
 {
 int pool = tainted ? store_pool + POOL_TAINT_BASE : store_pool;
 
@@ -346,12 +343,20 @@ if (size > yield_length[pool])
     if (++nblocks[pool] > maxblocks[pool])
       maxblocks[pool] = nblocks[pool];
 
+#ifndef MISSING_POSIX_MEMALIGN
     if (pool == POOL_CONFIG)
       {
       long pgsize = sysconf(_SC_PAGESIZE);
-      posix_memalign((void **)&newblock, pgsize, (mlength + pgsize - 1) & ~(pgsize - 1));
+      int err = posix_memalign((void **)&newblock,
+                               pgsize, (mlength + pgsize - 1) & ~(pgsize - 1));
+      if (err)
+       log_write(0, LOG_MAIN|LOG_PANIC_DIE,
+         "failed to alloc (using posix_memalign) %d bytes of memory: '%s'"
+         "called from line %d in %s",
+         size, strerror(err), linenumber, func);
       }
     else
+#endif
       newblock = internal_store_malloc(mlength, func, linenumber);
     newblock->next = NULL;
     newblock->length = length;