| 1 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
|
| 5 |
extern int foo (void); |
| 6 |
extern int bar (void); |
| 7 |
|
| 8 |
void test (void) |
| 9 |
{ |
| 10 |
void *p = malloc (1024); /* { dg-message "\\(1\\) allocated here" } */ |
| 11 |
void *q = malloc (1024); |
| 12 |
|
| 13 |
foo (); |
| 14 |
if (!q) /* { dg-message "\\(2\\) following 'true' branch \\(when 'q' is NULL\\)\\.\\.\\." } */ |
| 15 |
{ |
| 16 |
free (q); /* { dg-message "\\(3\\) \\.\\.\\.to here" } */ |
| 17 |
return; /* { dg-warning "leak of 'p'" "warning" } */ |
| 18 |
/* { dg-message "\\(4\\) 'p' leaks here; was allocated at \\(1\\)" "event" { target *-*-* } .-1 } */ |
| 19 |
} |
| 20 |
bar (); |
| 21 |
free (q); |
| 22 |
free (p); |
| 23 |
} |