aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/malloc-paths-7.c
blob: 12b93b272e4ee171bbc3a04dc61cbaceeb3161a5 (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
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
/* { dg-additional-options "-fno-exceptions" } */

#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);
}