aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/malloc-paths-7.c
blob: f6b99e35a43eaaac0c813164eb5f81660fccb19c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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);
}