]> code.delx.au - gnu-emacs/commitdiff
Catch malloc_get_state, malloc_set_state failure
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Jun 2016 00:18:24 +0000 (17:18 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Jun 2016 00:19:05 +0000 (17:19 -0700)
This should help insulate Emacs better from configuration screwups.
Future versions of the GNU C library are planned to deprecate
these functions, but will continue to support them in
already-built-and-dumped Emacs executables.
* src/alloc.c (malloc_initialize_hook) [DOUG_LEA_MALLOC]:
Abort if malloc_set_state fails.
(alloc_unexec_pre) [DOUG_LEA_MALLOC]:
Report malloc_get_state failure, and exit.

src/alloc.c

index 054e1ca23ca80fb3ff34e67832d5f8a9d6423242..3feed51b1e95e53700f2c344d8db4fb530596c1d 100644 (file)
@@ -20,6 +20,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
+#include <errno.h>
 #include <stdio.h>
 #include <limits.h>            /* For CHAR_BIT.  */
 #include <signal.h>            /* For SIGABRT, SIGDANGER.  */
@@ -150,7 +151,8 @@ malloc_initialize_hook (void)
                }
        }
 
-      malloc_set_state (malloc_state_ptr);
+      if (malloc_set_state (malloc_state_ptr) != 0)
+       emacs_abort ();
 # ifndef XMALLOC_OVERRUN_CHECK
       alloc_unexec_post ();
 # endif
@@ -174,6 +176,8 @@ alloc_unexec_pre (void)
 {
 #ifdef DOUG_LEA_MALLOC
   malloc_state_ptr = malloc_get_state ();
+  if (!malloc_state_ptr)
+    fatal ("malloc_get_state: %s", strerror (errno));
 #endif
 #ifdef HYBRID_MALLOC
   bss_sbrk_did_unexec = true;