Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/callbacks-2.c

raw
1 /* { dg-skip-if "requires hosted libstdc++ for stdlib free" { ! hostedlib } } */
2
3 /* Reproducer for PR analyzer/97258: we should report the double-free
4 inside a static callback if the callback is accessible via a global
5 initializer. */
6
7 #include <stdlib.h>
8
9 static void callback_1 (void *p)
10 {
11 free (p);
12 free (p); /* { dg-warning "double-'free' of 'p'" } */
13 }
14
15 struct ops {
16 void (*cb) (void *);
17 };
18
19 /* Callback struct is not static, and so could be accessed via
20 another TU. */
21
22 const struct ops ops_1 = {
23 .cb = callback_1
24 };