gcc/testsuite/c-c++-common/analyzer/use-after-free-3.c
raw| 1 | /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 | |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | void test_1 (int x, int y, int *out) |
| 6 | { |
| 7 | int *ptr = (int *)malloc (sizeof (int)); |
| 8 | if (!ptr) |
| 9 | return; |
| 10 | *ptr = 19; |
| 11 | |
| 12 | free (ptr); |
| 13 | *out = *ptr; /* { dg-warning "use after 'free' of 'ptr'" } */ |
| 14 | } |