Skip to content

Commit

Permalink
Add test case for memory leaking from a thead that is not joined, add…
Browse files Browse the repository at this point in the history
… thread_joins to other test cases.
  • Loading branch information
jerhard committed Nov 21, 2023
1 parent 2cc915f commit 45ec8a6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread --set ana.activated[+] threadid
#include <stdlib.h>
#include <pthread.h>

Expand All @@ -7,6 +7,7 @@ int *m1;

void *f1(void *arg) {
m1 = malloc(sizeof(int));
free(m1);
// Thread t1 leaks m1 here
pthread_exit(NULL); //WARN
}
Expand All @@ -28,6 +29,9 @@ int main(int argc, char const *argv[]) {

free(g);

pthread_join(t1, NULL);
pthread_join(t2, NULL);

// main thread is not leaking anything
return 0; //NOWARN
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread --set ana.activated[+] threadid
#include <stdlib.h>
#include <pthread.h>

Expand All @@ -25,9 +25,12 @@ int main(int argc, char const *argv[]) {

pthread_t t2;
pthread_create(&t2, NULL, f2, NULL);

free(g);

pthread_join(t1, NULL);
pthread_join(t2, NULL);

// main thread is not leaking anything
return 0; //NOWARN
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.base.privatization mutex-meet-tid --set ana.path_sens[+] threadflag
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.base.privatization mutex-meet-tid --set ana.path_sens[+] threadflag --set ana.activated[+] thread --set ana.activated[+] threadid
#include <stdlib.h>
#include <pthread.h>

Expand Down Expand Up @@ -28,6 +28,9 @@ int main(int argc, char const *argv[]) {

free(g);

pthread_join(t1, NULL);
pthread_join(t2, NULL);

// main thread is not leaking anything
return 0; //NOWARN
}
18 changes: 18 additions & 0 deletions tests/regression/76-memleak/15-mem-leak-not-joined-thread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread --set ana.activated[+] threadid
#include <stdlib.h>
#include <pthread.h>

int *m1;

void *f1(void *arg) {
m1 = malloc(sizeof(int));
while (1);
}

int main(int argc, char const *argv[]) {
pthread_t t1;
pthread_create(&t1, NULL, f1, NULL);

// memory from thread f1 which was not joined into main, is not freed
return 0; //WARN
}

0 comments on commit 45ec8a6

Please sign in to comment.