diff options
author | Kostya Serebryany <kcc@google.com> | 2012-03-28 18:30:10 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-03-28 18:30:10 +0000 |
commit | 44830c2f85f417bd486b49a53d97c640dd75728e (patch) | |
tree | c2c08cdca094c9673b8b2133dd90df4a44605120 | |
parent | 108a237510099cebb1522262fe1fde57fc5b8f90 (diff) | |
download | compiler-rt-44830c2f85f417bd486b49a53d97c640dd75728e.tar.gz |
[asan] add racy double-free test
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@153586 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/asan/tests/asan_racy_double_free_test.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/asan/tests/asan_racy_double_free_test.cc b/lib/asan/tests/asan_racy_double_free_test.cc new file mode 100644 index 000000000..12be9af26 --- /dev/null +++ b/lib/asan/tests/asan_racy_double_free_test.cc @@ -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); +} |