From 36b953947ee2ee0411139bd4ad7dcffdcc403036 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 11 Jan 2016 18:05:40 +0200 Subject: [PATCH] Avoid an infloop when we run out of memory * src/alloc.c (garbage_collect_1): Don't bother saving and restoring the echo-area message if we are GC'ing after running out of memory. This avoids an infloop due to repeated attempts to allocate memory for the cons cell needed to save the message, which signals the memory-full error, which attempts to save the echo-area message, which signals memory-full again, etc. --- src/alloc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 8ceacfe8ead..03dacc77c6e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5525,9 +5525,16 @@ garbage_collect_1 (void *end) don't let that cause a recursive GC. */ consing_since_gc = 0; - /* Save what's currently displayed in the echo area. */ - message_p = push_message (); - record_unwind_protect_void (pop_message_unwind); + /* Save what's currently displayed in the echo area. Don't do that + if we are GC'ing because we've run out of memory, since + push_message will cons, and we might have no memory for that. */ + if (NILP (Vmemory_full)) + { + message_p = push_message (); + record_unwind_protect_void (pop_message_unwind); + } + else + message_p = false; /* Save a copy of the contents of the stack, for debugging. */ #if MAX_SAVE_STACK > 0 @@ -5658,7 +5665,7 @@ garbage_collect_1 (void *end) } } - if (garbage_collection_messages) + if (garbage_collection_messages && NILP (Vmemory_full)) { if (message_p || minibuf_level > 0) restore_message (); -- 2.39.2