-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regr. test cases for multi-threaded valid-memcleanup
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
tests/regression/76-memleak/08-invalid-memcleanup-multi-threaded.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
#include <pthread.h> | ||
|
||
int *g; | ||
int *m1; | ||
int *m2; | ||
|
||
void *f1(void *arg) { | ||
m1 = malloc(sizeof(int)); | ||
// Thread t1 leaks m1 here | ||
pthread_exit(NULL); //WARN | ||
} | ||
|
||
void *f2(void *arg) { | ||
m2 = malloc(sizeof(int)); | ||
free(m2); // No leak for thread t2, since it calls free before exiting | ||
pthread_exit(NULL); //NOWARN | ||
} | ||
|
||
int main(int argc, char const *argv[]) { | ||
g = malloc(sizeof(int)); | ||
pthread_t t1; | ||
pthread_create(&t1, NULL, f1, NULL); | ||
|
||
pthread_t t2; | ||
pthread_create(&t2, NULL, f2, NULL); | ||
|
||
free(g); | ||
|
||
// main thread is not leaking anything | ||
return 0; //NOWARN | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/regression/76-memleak/09-invalid-memcleanup-multi-threaded-abort.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
#include <pthread.h> | ||
|
||
int *g; | ||
int *m1; | ||
int *m2; | ||
|
||
void *f1(void *arg) { | ||
m1 = malloc(sizeof(int)); | ||
// Thread t1 leaks m1 here | ||
exit(2); //WARN | ||
} | ||
|
||
void *f2(void *arg) { | ||
m2 = malloc(sizeof(int)); | ||
free(m2); // No leak for thread t2, since it calls free before exiting | ||
pthread_exit(NULL); //NOWARN | ||
} | ||
|
||
int main(int argc, char const *argv[]) { | ||
g = malloc(sizeof(int)); | ||
pthread_t t1; | ||
pthread_create(&t1, NULL, f1, NULL); | ||
|
||
pthread_t t2; | ||
pthread_create(&t2, NULL, f2, NULL); | ||
|
||
free(g); | ||
|
||
// main thread is not leaking anything | ||
return 0; //NOWARN | ||
} |