aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/attr-malloc-4.c
blob: 1517667dfb21e4fa8fda2a4d0a66bce1ed311d1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* An example where the deallocator requires non-NULL.  */

struct foo;
extern void foo_release (struct foo *)
  __attribute__((nonnull));
extern struct foo *foo_acquire (void)
  __attribute__ ((malloc (foo_release)));

void test_1 (void)
{
  struct foo *p = foo_acquire (); /* { dg-message "this call could return NULL" } */
  foo_release (p); /* { dg-warning "use of possibly-NULL 'p' where non-null" } */
}

void test_2 (void)
{
  struct foo *p = foo_acquire ();
  if (!p)
    return;
  foo_release (p);
}