aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/leak-pr109059-2.c
blob: 125bce84864f97142a51d37cbebe252586d64a5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Reduced from haproxy-2.7.1's cfgparse.c.  */

typedef __SIZE_TYPE__ size_t;

extern void*
calloc(size_t __nmemb, size_t __size)
  __attribute__((__nothrow__, __leaf__))
  __attribute__((__malloc__)) __attribute__((__alloc_size__(1, 2)));

struct list
{
  struct list* n;
  struct list* p;
};

struct cfg_postparser
{
  struct list list;
  char* name;
};

extern struct list postparsers;

int
test_1 (char* name)
{
  struct cfg_postparser* cp;

  cp = calloc(1, sizeof(*cp));
  if (!cp) {
    /* [...snip...] */
    return 0;
  }
  cp->name = name;

  (&cp->list)->p = (&postparsers)->p;
  (&postparsers)->p = (&cp->list);
  (&cp->list)->p->n = (&postparsers)->p;
  (&cp->list)->n = (&postparsers);

  return 1; /* { dg-bogus "leak of 'cp'" } */
}