From 2fef812ff9a11bebb6ac4b78ca010fde6bbfeea9 Mon Sep 17 00:00:00 2001 From: Julian Erhard Date: Tue, 21 Nov 2023 17:57:07 +0100 Subject: [PATCH] Add testcases for thread return and pthread_exit in thread different from main. --- .../15-mem-leak-not-joined-thread.c | 1 + .../16-no-mem-leak-thread-exit-main.c | 3 +-- .../76-memleak/17-mem-leak-thread-return.c | 26 ++++++++++++++++++ .../76-memleak/18-mem-leak-thread-exit.c | 27 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/regression/76-memleak/17-mem-leak-thread-return.c create mode 100644 tests/regression/76-memleak/18-mem-leak-thread-exit.c diff --git a/tests/regression/76-memleak/15-mem-leak-not-joined-thread.c b/tests/regression/76-memleak/15-mem-leak-not-joined-thread.c index 21c1992fc3..15f249ffe1 100644 --- a/tests/regression/76-memleak/15-mem-leak-not-joined-thread.c +++ b/tests/regression/76-memleak/15-mem-leak-not-joined-thread.c @@ -7,6 +7,7 @@ int *m1; void *f1(void *arg) { m1 = malloc(sizeof(int)); while (1); + return NULL; } int main(int argc, char const *argv[]) { diff --git a/tests/regression/76-memleak/16-no-mem-leak-thread-exit-main.c b/tests/regression/76-memleak/16-no-mem-leak-thread-exit-main.c index 5fb89113d2..663ea26663 100644 --- a/tests/regression/76-memleak/16-no-mem-leak-thread-exit-main.c +++ b/tests/regression/76-memleak/16-no-mem-leak-thread-exit-main.c @@ -7,6 +7,7 @@ int *m1; void *f1(void *arg) { m1 = malloc(sizeof(int)); while (1); + return NULL; } int main(int argc, char const *argv[]) { @@ -15,8 +16,6 @@ int main(int argc, char const *argv[]) { pthread_exit(NULL); - pthread_join(t1, NULL); - // A pthread_join called in main will wait for other threads to finish // Therefore, no memory leak here return 0; // NOWARN diff --git a/tests/regression/76-memleak/17-mem-leak-thread-return.c b/tests/regression/76-memleak/17-mem-leak-thread-return.c new file mode 100644 index 0000000000..bec64ca22f --- /dev/null +++ b/tests/regression/76-memleak/17-mem-leak-thread-return.c @@ -0,0 +1,26 @@ +//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread +#include +#include + +int *m1; + +void *f2(void *arg) { + m1 = malloc(sizeof(int)); + while (1); + return NULL; +} + +void *f1(void *arg) { + pthread_t t2; + pthread_create(&t2, NULL, f2, NULL); + + return NULL; +} + +int main(int argc, char const *argv[]) { + pthread_t t1; + pthread_create(&t1, NULL, f1, NULL); + pthread_join(t1, NULL); + + return 0; // WARN +} \ No newline at end of file diff --git a/tests/regression/76-memleak/18-mem-leak-thread-exit.c b/tests/regression/76-memleak/18-mem-leak-thread-exit.c new file mode 100644 index 0000000000..e98ae3f346 --- /dev/null +++ b/tests/regression/76-memleak/18-mem-leak-thread-exit.c @@ -0,0 +1,27 @@ +//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread +#include +#include + +int *m1; + +void *f2(void *arg) { + m1 = malloc(sizeof(int)); + while (1); + return NULL; +} + +void *f1(void *arg) { + pthread_t t2; + pthread_create(&t2, NULL, f2, NULL); + + pthread_exit(NULL); + return NULL; +} + +int main(int argc, char const *argv[]) { + pthread_t t1; + pthread_create(&t1, NULL, f1, NULL); + pthread_join(t1, NULL); + + return 0; // WARN +} \ No newline at end of file