Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: Sterling Augustine <saugustine@google.com>, gdb-patches@sourceware.org
Subject: Re: [readline patch, gdb-7.3?] Avoid free from a signal handler  [Re: [PATCH] Make interrupting tab-completion safe.]
Date: Wed, 29 Jun 2011 21:49:00 -0000	[thread overview]
Message-ID: <20110629214841.GA18179@host1.jankratochvil.net> (raw)
In-Reply-To: <20110627160307.GG20676@adacore.com>

On Mon, 27 Jun 2011 18:03:07 +0200, Joel Brobecker wrote:
> > readline/
> > 2011-06-27  Jan Kratochvil  <jan.kratochvil@redhat.com>
> > 
> > 	Avoid free from a signal handler.
> > 	* Makefile.in (xfree.o): Add readline.h.
> > 	* xfree.c: Include stdio.h and readline.h.
> > 	(xfree): Return on RL_STATE_SIGHANDLER.
> > 	* xmalloc.h (xfree): New definition.
> 
> Interesting. OK for gdb-7.3 if OK for readline...

Checked in the original patch for trunk:
	http://sourceware.org/ml/gdb-cvs/2011-06/msg00168.html

For gdb-7.3 it is more complicated as it still has readline-5.1, checked in
there the patch below, it is not nice but I find it OK for the branch.


Thanks,
Jan


gdb_7_3-branch:
http://sourceware.org/ml/gdb-cvs/2011-06/msg00169.html

--- src/readline/ChangeLog.gdb	2011/03/04 18:12:47	1.38
+++ src/readline/ChangeLog.gdb	2011/06/29 21:46:43	1.38.2.1
@@ -1,3 +1,12 @@
+2011-06-27  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	Avoid free from a signal handler.
+	* Makefile.in (xmalloc.o): Add readline.h.
+	* xmalloc.c: Include readline.h.
+	(xmalloc, xrealloc): Disable them by #if 0.
+	(xfree): Return on RL_STATE_SIGHANDLER, #undef free.
+	* xmalloc.h (xfree, free): New definition.
+
 2011-03-04  Michael Snyder  <msnyder@vmware.com>
 
 	* bind.c (rl_function_dumper): Free allocated memory.
--- src/readline/Makefile.in	2009/07/30 22:53:17	1.11
+++ src/readline/Makefile.in	2011/06/29 21:46:43	1.11.8.1
@@ -417,7 +417,7 @@
 vi_mode.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
 vi_mode.o: history.h ansi_stdlib.h rlstdc.h
 xmalloc.o: ${BUILD_DIR}/config.h
-xmalloc.o: ansi_stdlib.h
+xmalloc.o: ansi_stdlib.h readline.h
 
 bind.o: rlshell.h
 histfile.o: rlshell.h
--- src/readline/xmalloc.c	2006/04/20 20:13:20	1.5
+++ src/readline/xmalloc.c	2011/06/29 21:46:43	1.5.40.1
@@ -33,6 +33,7 @@
 #endif /* HAVE_STDLIB_H */
 
 #include "xmalloc.h"
+#include "readline.h"
 
 /* **************************************************************** */
 /*								    */
@@ -40,6 +41,9 @@
 /*								    */
 /* **************************************************************** */
 
+/* xmalloc and xrealloc are provided by GDB.  */
+#if 0
+
 static void
 memory_error_and_abort (fname)
      char *fname;
@@ -77,12 +81,20 @@
   return (temp);
 }
 
+/* xmalloc and xrealloc are provided by GDB.  */
+#endif /* 0 */
+
 /* Use this as the function to call when adding unwind protects so we
    don't need to know what free() returns. */
 void
 xfree (string)
      PTR_T string;
 {
+  /* Leak a bit.  */
+  if (RL_ISSTATE(RL_STATE_SIGHANDLER))
+    return;
+
+#undef free
   if (string)
     free (string);
 }
--- src/readline/xmalloc.h	2006/04/20 20:13:20	1.4
+++ src/readline/xmalloc.h	2011/06/29 21:46:43	1.4.40.1
@@ -39,6 +39,12 @@
 
 #endif /* !PTR_T */
 
+/* xmalloc and xrealloc should be also protected from RL_STATE_SIGHANDLER.  */
+#define xfree xfree_readline
+
+/* readline-5.1 backport.  */
+#define free xfree
+
 extern PTR_T xmalloc PARAMS((size_t));
 extern PTR_T xrealloc PARAMS((void *, size_t));
 extern void xfree PARAMS((void *));


  reply	other threads:[~2011-06-29 21:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-11  0:19 [PATCH] Make interrupting tab-completion safe Sterling Augustine
2011-06-12 12:12 ` Jan Kratochvil
2011-06-13 17:45   ` Sterling Augustine
2011-06-26 22:22     ` [readline patch, gdb-7.3?] Avoid free from a signal handler [Re: [PATCH] Make interrupting tab-completion safe.] Jan Kratochvil
2011-06-27 16:03       ` Joel Brobecker
2011-06-29 21:49         ` Jan Kratochvil [this message]
2011-06-29 13:54       ` [Bug-readline] " Chet Ramey
2011-06-29 20:35         ` Jan Kratochvil
2011-06-30 14:38           ` Chet Ramey
2011-07-06 16:03             ` Jan Kratochvil
2011-07-06 16:07               ` Chet Ramey
2011-07-06 17:42                 ` Jan Kratochvil
2011-07-07 13:40                   ` Chet Ramey
2011-07-08 16:03                     ` Chet Ramey
2011-10-19 20:30                       ` Jan Kratochvil
2011-10-19 17:02                     ` Jan Kratochvil
2011-10-19 17:51                       ` Pedro Alves
2011-10-19 18:50                       ` Chet Ramey
2011-07-11 18:53     ` [PATCH] Make interrupting tab-completion safe Sterling Augustine
2011-07-11 18:54       ` Jan Kratochvil
     [not found]         ` <CAEG7qUxFvEoJ-E2YsoFPL-tKoK4kD3-pKn-h31uUeXQoDD2Gaw@mail.gmail.com>
2011-07-12 15:59           ` [dwarf2_mark_helper patch] " Jan Kratochvil
2011-07-12 17:48             ` Sterling Augustine
2011-07-12 18:56             ` Jan Kratochvil
2011-07-12 21:18             ` [commit] " Jan Kratochvil
2011-07-12 21:42               ` Tom Tromey
2011-07-12 22:51                 ` Jan Kratochvil

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

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

  git send-email \
    --in-reply-to=20110629214841.GA18179@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=saugustine@google.com \
    /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