This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa libmudflap] realloc fix
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 23 May 2003 12:39:54 -0400
- Subject: [tree-ssa libmudflap] realloc fix
Hi -
This patch fixes the gethostbyname-related crash Eyal noticed.
+2003-05-23 Frank Ch. Eigler <fche@redhat.com>
+
+ * mf-hooks.c (realloc): Correct reentrancy logic.
+ * testsuite/libmudflap.c/hook-allocstuff.c: New test case.
+
Index: mf-hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-hooks.c,v
retrieving revision 1.1.2.34
diff -u -r1.1.2.34 mf-hooks.c
--- mf-hooks.c 20 May 2003 19:09:47 -0000 1.1.2.34
+++ mf-hooks.c 23 May 2003 16:39:16 -0000
@@ -180,7 +180,7 @@
/* Ensure heap wiping doesn't occur during this peculiar
unregister/reregister pair. */
LOCKTH ();
- /* XXX: reentrancy! */
+ __mf_state = reentrant;
saved_wipe_heap = __mf_opts.wipe_heap;
__mf_opts.wipe_heap = 0;
@@ -196,6 +196,8 @@
/* Restore previous setting. */
__mf_opts.wipe_heap = saved_wipe_heap;
+
+ __mf_state = active;
UNLOCKTH ();
return result;
Index: testsuite/libmudflap.c/hook-allocstuff.c
===================================================================
RCS file: testsuite/libmudflap.c/hook-allocstuff.c
diff -N testsuite/libmudflap.c/hook-allocstuff.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/libmudflap.c/hook-allocstuff.c 23 May 2003 16:39:16 -0000
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main ()
+{
+ char *foo = (char *) malloc (10);
+ strcpy (foo, "hello");
+ foo = (char *) realloc (foo, 20);
+ printf ("%s", foo);
+ if (strcmp (foo, "hello"))
+ abort ();
+ free (foo);
+ printf (" world\n");
+ return 0;
+}
+/* { dg-output "hello world" } */