-
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.
Merge remote-tracking branch 'mrstanb/improve-valid-memtrack-for-sing…
…le-threaded-programs' into svcomp24-dev
- Loading branch information
Showing
8 changed files
with
268 additions
and
6 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
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 | ||
} |
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
//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; | ||
|
||
// According to `valid-memtrack`, the memory of p is unreachable and we don't have a false positive | ||
int *p = malloc(sizeof(int)); | ||
|
||
return 0; //WARN | ||
} |
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,16 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
typedef struct st { | ||
int *a; | ||
int b; | ||
} st; | ||
|
||
st st_nonptr; | ||
|
||
int main(int argc, char const *argv[]) { | ||
st_nonptr.a = malloc(sizeof(int)); | ||
st_nonptr.a = NULL; | ||
|
||
return 0; //WARN | ||
} |
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,19 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
typedef struct st { | ||
int *a; | ||
int b; | ||
} st; | ||
|
||
st *st_ptr; | ||
|
||
int main(int argc, char const *argv[]) { | ||
st_ptr = malloc(sizeof(st)); | ||
st_ptr->a = malloc(sizeof(int)); | ||
st_ptr->a = NULL; | ||
free(st_ptr); | ||
|
||
// Only st_ptr->a is causing trouble here | ||
return 0; //WARN | ||
} |
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,25 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
typedef struct st { | ||
int *a; | ||
int b; | ||
} st; | ||
|
||
typedef struct st2 { | ||
st *st_ptr; | ||
} st2; | ||
|
||
st2 *st_var; | ||
|
||
int main(int argc, char const *argv[]) { | ||
st_var = malloc(sizeof(st2)); | ||
st_var->st_ptr = malloc(sizeof(st)); | ||
st_var->st_ptr->a = malloc(sizeof(int)); | ||
st_var->st_ptr->a = NULL; | ||
free(st_var->st_ptr); | ||
free(st_var); | ||
|
||
// Only st_var->st_ptr->a is causing trouble here | ||
return 0; //WARN | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/regression/76-memleak/13-global-nested-struct-ptr-reachable.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,29 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
typedef struct st { | ||
int *a; | ||
int b; | ||
} st; | ||
|
||
typedef struct st2 { | ||
st *st_ptr; | ||
} st2; | ||
|
||
st2 *st_var; | ||
|
||
int main(int argc, char const *argv[]) { | ||
st_var = malloc(sizeof(st2)); | ||
st_var->st_ptr = malloc(sizeof(st)); | ||
int *local_ptr = malloc(sizeof(int)); | ||
st_var->st_ptr->a = local_ptr; | ||
local_ptr = NULL; | ||
|
||
free(st_var->st_ptr); | ||
free(st_var); | ||
|
||
// local_ptr's memory is reachable through st_var->st_ptr->a | ||
// It's leaked, because we don't call free() on it | ||
// Hence, there should be a single warning for a memory leak, but not for unreachable memory | ||
return 0; //WARN | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/regression/76-memleak/14-global-nested-struct-non-ptr-reachable.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,25 @@ | ||
//PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
#include <stdlib.h> | ||
|
||
typedef struct st { | ||
int *a; | ||
int b; | ||
} st; | ||
|
||
typedef struct st2 { | ||
st *st_ptr; | ||
} st2; | ||
|
||
st2 st_var; | ||
|
||
int main(int argc, char const *argv[]) { | ||
st_var.st_ptr = malloc(sizeof(st)); | ||
int *local_ptr = malloc(sizeof(int)); | ||
st_var.st_ptr->a = local_ptr; | ||
local_ptr = NULL; | ||
free(st_var.st_ptr); | ||
|
||
// local_ptr's memory is reachable through st_var.st_ptr->a, but it's not freed | ||
// Hence, there should be only a single warning for a memory leak, but not for unreachable memory | ||
return 0; //WARN | ||
} |