-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for unreachable heap memory from globals
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
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,12 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
int *g; | ||
|
||
int main(int argc, char const *argv[]) { | ||
g = malloc(sizeof(int)); | ||
// Reference to g's heap contents is lost here | ||
g = NULL; | ||
|
||
return 0; //WARN | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/regression/76-memleak/09-unreachable-with-local-var.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,17 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
int *g; | ||
|
||
int main(int argc, char const *argv[]) { | ||
g = malloc(sizeof(int)); | ||
// Reference to g's heap contents is lost here | ||
g = NULL; | ||
// We get a false positive for p's memory being unreachable | ||
// It's still leaked, but due to free() being commented out | ||
// TODO: Should we only improve the error reporting for unreachable memory in this case? | ||
int *p = malloc(sizeof(int)); | ||
//free(p); | ||
|
||
return 0; //WARN | ||
} |