bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: Re: fatal-signal: make multithread-safe
Date: Sun, 28 Jun 2020 00:42:02 +0200	[thread overview]
Message-ID: <2116674.OGhGKdnA1K@omega> (raw)
In-Reply-To: <2350079.bc2zunp2nT@omega>

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 array.

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
      5.1.2.3.(5)) ensure that we increment the actions_count only after



  reply	other threads:[~2020-06-27 22:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-27 21:57 fatal-signal: make multithread-safe Bruno Haible
2020-06-27 22:42 ` Bruno Haible [this message]
2020-07-04 10:45   ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2116674.OGhGKdnA1K@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).