From e89ab31e427d4f978cc69bb04854f63cb941bb9f Mon Sep 17 00:00:00 2001 From: pithikos Date: Tue, 6 Jan 2015 18:49:58 +0000 Subject: [PATCH] External bugs added --- tests/ext_bugs/memleak.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/ext_bugs/memleak.c diff --git a/tests/ext_bugs/memleak.c b/tests/ext_bugs/memleak.c new file mode 100644 index 0000000..6cb5c7f --- /dev/null +++ b/tests/ext_bugs/memleak.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +volatile int threads_keepalive = 1; + +void* thread_do(void *arg){ + while(threads_keepalive) + sleep(1); + pthread_exit(NULL); + return; +} + +int main(void){ + + /* Make threads */ + pthread_t* threads; + threads = malloc(2 * sizeof(pthread_t)); + pthread_create(&threads[0], NULL, &thread_do, NULL); + pthread_create(&threads[1], NULL, &thread_do, NULL); + pthread_detach(threads[0]); + pthread_detach(threads[1]); + sleep(1); // MAKING SURE THREADS HAVE INITIALIZED + + /* Kill threads */ + threads_keepalive = 0; + sleep(3); // MAKING SURE THREADS HAVE UNBLOCKED + pthread_join(threads[0], NULL); + pthread_join(threads[1], NULL); + free(threads); + + return 0; +}