Skip to content

Commit

Permalink
Add 3 regr. tests for trying out global struct variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstanb committed Nov 8, 2023
1 parent 05e4892 commit f343d74
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/regression/76-memleak/10-global-struct-no-ptr.c
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
}
19 changes: 19 additions & 0 deletions tests/regression/76-memleak/11-global-struct-ptr.c
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
}
25 changes: 25 additions & 0 deletions tests/regression/76-memleak/12-global-nested-struct-ptr.c
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
}

0 comments on commit f343d74

Please sign in to comment.