aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/malloc-paths-7.c
blob: 766bbe7d99ad8d6aae1a562cd4aa0e32052a10e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */

#include <stdlib.h>

extern int foo (void);
extern int bar (void);

void test (void)
{
  void *p = malloc (1024); /* { dg-message "\\(1\\) allocated here" } */ 
  void *q = malloc (1024);

  foo ();
  if (!q) /* { dg-message "\\(2\\) following 'true' branch \\(when 'q' is NULL\\)\\.\\.\\." } */ 
    {
      free (q); /* { dg-message "\\(3\\) \\.\\.\\.to here" } */ 
      return; /* { dg-warning "leak of 'p'" "warning" } */ 
      /* { dg-message "\\(4\\) 'p' leaks here; was allocated at \\(1\\)" "event" { target *-*-* } .-1 } */
    }
  bar ();
  free (q);
  free (p);
}