From ccc0fa28a846bbc9123004d6c38fdae2bfc2bec4 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 3 Jul 2025 16:19:09 +0300 Subject: [PATCH] Avoid segfaults due to C-g when a thread does GC * src/keyboard.c (handle_interrupt): Don't forcibly switch threads if a non-main thread was in GC when the signal handler was called. (cherry picked from commit 205d69e7e64cf23df0bc7a52b1149f6130c117b5) --- src/keyboard.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/keyboard.c b/src/keyboard.c index d7f15aeb4e1..fa0a5fbdd1a 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -12350,7 +12350,15 @@ handle_interrupt (bool in_signal_handler) thread, see deliver_process_signal. So we must make sure the main thread holds the global lock. */ if (in_signal_handler) - maybe_reacquire_global_lock (); + { + /* But if the signal handler was called when a non-main thread was + in GC, just return, since switching threads by force-taking the + global lock will confuse the heck out of GC, and will most + likely segfault. */ + if (!main_thread_p (current_thread) && gc_in_progress) + return; + maybe_reacquire_global_lock (); + } #endif if (waiting_for_input && !echoing) quit_throw_to_read_char (in_signal_handler); -- 2.39.5