aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/attr-malloc-exception.c
blob: 9f5e2e871ce0513d1d7636c182bed0343f81e747 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* { dg-additional-options "-fexceptions" } */

extern void free (void *);

/* Not marked "nothrow", so assume it could throw.  */
char *xstrdup (const char *)
  __attribute__((malloc (free), returns_nonnull));

void test_1 (const char *s, const char *t)
{
  char *p = xstrdup (s); /* { dg-message "allocated here" } */
  char *q = xstrdup (t); /* { dg-warning "leak of 'p'" } */
  /* { dg-message "if .* throws an exception\.\.\." "" { target *-*-* } .-1 } */

  free (q);
  free (p);
}