Patchwork libgo patch committed: Better error message if malloc gets SIGSEGV

login
register
mail settings
Submitter Ian Taylor
Date Dec. 14, 2010, 5:19 a.m.
Message ID <mcr39q10w3l.fsf@google.com>
Download mbox | patch
Permalink /patch/75469/
State New
Headers show

Comments

Ian Taylor - Dec. 14, 2010, 5:19 a.m.
Previously, if a SIGSEGV occurred during an malloc, perhaps due to a
corrupt heap, this would start a panic as usual, and the panic would
itself allocate memory, potentially leading to another SIGSEGV, and then
to a "malloc/free - deadlock" message.  That is not very useful.  This
patch checks for whether a signal occurs during memory allocation.  If
it does, we just abort the program immediately, as a panic is unlikely
to succeed.  Committed to mainline.

Ian

Patch

diff -r a3f3fa2f104e libgo/runtime/go-signal.c
--- a/libgo/runtime/go-signal.c	Mon Dec 13 21:12:33 2010 -0800
+++ b/libgo/runtime/go-signal.c	Mon Dec 13 21:16:34 2010 -0800
@@ -133,6 +133,12 @@ 
     {
       sigset_t clear;
 
+      if (__sync_bool_compare_and_swap (&m->mallocing, 1, 1))
+	{
+	  fprintf (stderr, "caught signal while mallocing: %s\n", msg);
+	  __go_assert (0);
+	}
+
       /* The signal handler blocked signals; unblock them.  */
       i = sigfillset (&clear);
       __go_assert (i == 0);