| 1 |
/* { dg-additional-options "-fanalyzer-verbosity=1" } */ |
| 2 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib free" { ! hostedlib } } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
void |
| 7 |
calls_free (void *victim) |
| 8 |
{ |
| 9 |
free (victim); /* { dg-warning "double-'free' of 'victim'" } */ |
| 10 |
} |
| 11 |
|
| 12 |
extern void do_stuff (void); |
| 13 |
|
| 14 |
struct foo |
| 15 |
{ |
| 16 |
void *m_p; |
| 17 |
}; |
| 18 |
|
| 19 |
static void * __attribute__((noinline)) |
| 20 |
test_a (struct foo f) |
| 21 |
{ |
| 22 |
do_stuff (); |
| 23 |
|
| 24 |
calls_free (f.m_p); |
| 25 |
|
| 26 |
do_stuff (); |
| 27 |
|
| 28 |
return f.m_p; |
| 29 |
} |
| 30 |
|
| 31 |
void test_b (void *p) |
| 32 |
{ |
| 33 |
void *q; |
| 34 |
struct foo f; |
| 35 |
f.m_p = p; |
| 36 |
q = test_a (f); |
| 37 |
calls_free (q); /* { dg-message "passing freed pointer 'q' in call to 'calls_free' from 'test_b'" } */ |
| 38 |
do_stuff (); |
| 39 |
} |