Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/leak-pr109059-1.c

raw
1 /* Reduced from haproxy-2.7.1's cfgparse.c. */
2
3 typedef __SIZE_TYPE__ size_t;
4
5 extern void*
6 calloc(size_t __nmemb, size_t __size)
7 __attribute__((__nothrow__, __leaf__))
8 __attribute__((__malloc__)) __attribute__((__alloc_size__(1, 2)));
9
10 struct list
11 {
12 struct list* n;
13 struct list* p;
14 };
15
16 struct cfg_postparser
17 {
18 struct list list;
19 char* name;
20 int (*func)();
21 };
22
23 extern struct list postparsers;
24
25 int
26 cfg_register_postparser(char* name, int (*func)())
27 {
28 struct cfg_postparser* cp;
29
30 cp = (struct cfg_postparser *) calloc(1, sizeof(*cp));
31 if (!cp) {
32 /* [...snip...] */
33 return 0;
34 }
35 cp->name = name;
36 cp->func = func;
37
38 ({
39 (&cp->list)->p = (&postparsers)->p;
40 (&cp->list)->p->n = (&postparsers)->p = (&cp->list);
41 (&cp->list)->n = (&postparsers);
42 (&cp->list);
43 });
44
45 return 1; /* { dg-bogus "leak of 'cp'" } */
46 }