From b4788b9394f3c9d50468607cbcf82e9490fa7c1d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 10 Jun 2016 17:18:24 -0700 Subject: [PATCH] Catch malloc_get_state, malloc_set_state failure 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/alloc.c b/src/alloc.c index 054e1ca23ca..3feed51b1e9 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see . */ #include +#include #include #include /* For CHAR_BIT. */ #include /* 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; -- 2.39.2