| 1 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
|
| 5 |
void *global_ptr; |
| 6 |
|
| 7 |
void test_1 (int i) |
| 8 |
{ |
| 9 |
global_ptr = malloc (1024); /* { dg-message "allocated here" } */ |
| 10 |
*(int *)&global_ptr = i; /* { dg-warning "leak of 'global_ptr'" } */ |
| 11 |
} |
| 12 |
|
| 13 |
void test_2 (int i) |
| 14 |
{ |
| 15 |
void *p = malloc (1024); /* { dg-message "allocated here" } */ |
| 16 |
global_ptr = p; |
| 17 |
*(int *)&p = i; |
| 18 |
p = global_ptr; |
| 19 |
free (p); |
| 20 |
free (global_ptr); /* { dg-warning "double-'free' of 'p'" } */ |
| 21 |
} |