| 1 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
|
| 5 |
/* Reduced from Juliet 1.3's CWE415_Double_Free__malloc_free_char_67a.c |
| 6 |
goodG2B which was showing a false leak report in a non-LTO build. */ |
| 7 |
|
| 8 |
struct s1 |
| 9 |
{ |
| 10 |
char * structFirst; |
| 11 |
}; |
| 12 |
void external_fn_1(struct s1 myStruct); |
| 13 |
void test_1() |
| 14 |
{ |
| 15 |
char * data; |
| 16 |
struct s1 myStruct; |
| 17 |
data = (char *)malloc(100*sizeof(char)); |
| 18 |
if (data == NULL) |
| 19 |
exit(-1); |
| 20 |
myStruct.structFirst = data; |
| 21 |
external_fn_1(myStruct); |
| 22 |
} /* { dg-bogus "leak of 'data'" } */ |
| 23 |
|
| 24 |
/* As above, but with padding before the field. */ |
| 25 |
|
| 26 |
struct s2 |
| 27 |
{ |
| 28 |
void *padding; |
| 29 |
char *ptr; |
| 30 |
}; |
| 31 |
void external_fn_2(struct s2 myStruct); |
| 32 |
void test_2() |
| 33 |
{ |
| 34 |
char * data; |
| 35 |
struct s2 myStruct; |
| 36 |
data = (char *)malloc(100*sizeof(char)); |
| 37 |
if (data == NULL) |
| 38 |
exit(-1); |
| 39 |
myStruct.padding = NULL; |
| 40 |
myStruct.ptr = data; |
| 41 |
external_fn_2(myStruct); |
| 42 |
} /* { dg-bogus "leak of 'data'" } */ |
| 43 |
|