Skip to content

Commit

Permalink
Add test cases for unreachable heap memory from globals
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstanb committed Nov 7, 2023
1 parent 421abcd commit 9f7224e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/regression/76-memleak/08-unreachable-mem.c
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 tests/regression/76-memleak/09-unreachable-with-local-var.c
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
}

0 comments on commit 9f7224e

Please sign in to comment.