[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fatal-signal: make multithread-safe

From: Bruno Haible
Subject: Re: fatal-signal: make multithread-safe
Date: Sun, 28 Jun 2020 00:42:02 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; )

That was good, but there's still a multithreading issue, as the signal handler
may be executing in a different thread.

2020-06-27  Bruno Haible  <bruno@clisp.org>

        fatal-signal: Make multithread-safe.
        * lib/fatal-signal.c (at_fatal_signal): Don't free the old actions 

diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index 975393b..c6f8dac 100644
--- a/lib/fatal-signal.c
+++ b/lib/fatal-signal.c
@@ -239,8 +239,15 @@ at_fatal_signal (action_t action)
       actions = new_actions;
       actions_allocated = new_actions_allocated;
       /* Now we can free the old actions array.  */
+      /* No, we can't do that.  If fatal_signal_handler is running in a
+         different thread and has already fetched the actions pointer (getting
+         old_actions) but not yet accessed its n-th element, that thread may
+         crash when accessing an element of the already freed old_actions
+         array.  */
+      #if 0
       if (old_actions != static_actions)
         free (old_actions);
+      #endif
   /* The two uses of 'volatile' in the types above (and ISO C 99 section ensure that we increment the actions_count only after

reply via email to

[Prev in Thread] Current Thread [Next in Thread]