Skip to content

Commit

Permalink
Add testcases for thread return and pthread_exit in thread different …
Browse files Browse the repository at this point in the history
…from main.
  • Loading branch information
jerhard committed Nov 21, 2023
1 parent 56c4d62 commit 2fef812
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tests/regression/76-memleak/17-mem-leak-thread-return.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread
#include <stdlib.h>
#include <pthread.h>

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
}
27 changes: 27 additions & 0 deletions tests/regression/76-memleak/18-mem-leak-thread-exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread
#include <stdlib.h>
#include <pthread.h>

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
}

0 comments on commit 2fef812

Please sign in to comment.