]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid segfaults due to C-g when a thread does GC
authorEli Zaretskii <eliz@gnu.org>
Thu, 3 Jul 2025 13:19:09 +0000 (16:19 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 23 Jul 2025 20:13:28 +0000 (22:13 +0200)
* 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

index d7f15aeb4e114229497f4a2c5a6602c1dcf0396d..fa0a5fbdd1a29b5c5cc9f27db46c407e265fdc3a 100644 (file)
@@ -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);