[llvm-commits] [compiler-rt] r153586 - /compiler-rt/trunk/lib/asan/tests/asan_racy_double_free_test.cc

Kostya Serebryany kcc at google.com
Wed Mar 28 11:30:10 PDT 2012


Author: kcc
Date: Wed Mar 28 13:30:10 2012
New Revision: 153586

URL: http://llvm.org/viewvc/llvm-project?rev=153586&view=rev
Log:
[asan] add racy double-free test

Added:
    compiler-rt/trunk/lib/asan/tests/asan_racy_double_free_test.cc

Added: compiler-rt/trunk/lib/asan/tests/asan_racy_double_free_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_racy_double_free_test.cc?rev=153586&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_racy_double_free_test.cc (added)
+++ compiler-rt/trunk/lib/asan/tests/asan_racy_double_free_test.cc Wed Mar 28 13:30:10 2012
@@ -0,0 +1,32 @@
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+const int N = 1000;
+void *x[N];
+
+void *Thread1(void *) {
+  for (int i = 0; i < N; i++) {
+    fprintf(stderr, "%s %d\n", __FUNCTION__, i);
+    free(x[i]);
+  }
+  return NULL;
+}
+
+void *Thread2(void *) {
+  for (int i = 0; i < N; i++) {
+    fprintf(stderr, "%s %d\n", __FUNCTION__, i);
+    free(x[i]);
+  }
+  return NULL;
+}
+
+int main() {
+  for (int i = 0; i < N; i++)
+    x[i] = malloc(128);
+  pthread_t t[2];
+  pthread_create(&t[0], 0, Thread1, 0);
+  pthread_create(&t[1], 0, Thread2, 0);
+  pthread_join(t[0], 0);
+  pthread_join(t[1], 0);
+}





More information about the llvm-commits mailing list