Add free-is-write functionality (experimental, not enabled by default).
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11627 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/helgrind/tests/free_is_write.c b/helgrind/tests/free_is_write.c
new file mode 100644
index 0000000..0dc53f8
--- /dev/null
+++ b/helgrind/tests/free_is_write.c
@@ -0,0 +1,42 @@
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <unistd.h>
+
+static char* s_mem;
+
+/* wait a second, so as to guarantee that the parent access
+ the malloc'd area, then free it. */
+static void* thread_func(void* arg)
+{
+ sleep(1);
+ free(s_mem);
+ return NULL;
+}
+
+int main(int argc, char** argv)
+{
+ pthread_t tid;
+ int quiet;
+
+ fprintf(stderr, "Start.\n");
+
+ quiet = argc > 1;
+
+ s_mem = malloc(10);
+ if (0 && !quiet)
+ fprintf(stderr, "Pointer to allocated memory: %p\n", s_mem);
+ assert(s_mem);
+ pthread_create(&tid, NULL, thread_func, NULL);
+
+ /* Write, which isn't coordinated with the free ==> a race
+ should be reported. */
+ char c = s_mem[5];
+ __asm__ __volatile__("" : : "r"((long)c) );
+
+ pthread_join(tid, NULL);
+ fprintf(stderr, "Done.\n");
+ return 0;
+}