1 typedef __SIZE_TYPE__ size_t;
2 
3 #define NULL ((void *)0)
4 
5 extern void *malloc (size_t __size)
6   __attribute__ ((__nothrow__ , __leaf__))
7   __attribute__ ((__malloc__))
8   __attribute__ ((__alloc_size__ (1)));
9 extern void *realloc (void *__ptr, size_t __size)
10   __attribute__ ((__nothrow__ , __leaf__))
11   __attribute__ ((__warn_unused_result__))
12   __attribute__ ((__alloc_size__ (2)));
13 extern void free (void *__ptr)
14   __attribute__ ((__nothrow__ , __leaf__));
15 
test_1(void * ptr)16 void *test_1 (void *ptr)
17 {
18   return realloc (ptr, 1024);
19 }
20 
test_2(void * ptr)21 void *test_2 (void *ptr)
22 {
23   void *p = malloc (1024);
24   p = realloc (p, 4096);
25   /* TODO: should warn about the leak when the above call fails (PR analyzer/99260).  */
26   free (p);
27 }
28 
test_3(void * ptr)29 void *test_3 (void *ptr)
30 {
31   void *p = malloc (1024);
32   void *q = realloc (p, 4096);
33   if (q)
34     free (q);
35   else
36     free (p);
37 }
38 
test_4(void)39 void *test_4 (void)
40 {
41   return realloc (NULL, 1024);
42 }
43 
test_5(int * p)44 int *test_5 (int *p)
45 {
46   *p = 42;
47   int *q = realloc (p, sizeof(int) * 4);
48   *q = 43; /* { dg-warning "possibly-NULL 'q'" "PR analyzer/99260" { xfail *-*-* } } */
49   return q;
50 }
51 
test_6(size_t sz)52 void test_6 (size_t sz)
53 {
54   void *p = realloc (NULL, sz);
55 } /* { dg-warning "leak of 'p'" } */
56