aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/data-model-20a.c
blob: 767b9912ed9c38a0bd31af4c9c52b3ee5556d984 (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
25
/* { dg-additional-options "-Wno-analyzer-too-complex" } */

#include <stdlib.h>

struct foo { int dummy; };

struct foo **
test (int n) {
  struct foo **arr;
  int i;

  if ((arr = (struct foo **)malloc(n * sizeof(struct foo *))) == NULL)
    return NULL;

  for (i = 0; i < n; i++) {
    if ((arr[i] = (struct foo *)malloc(sizeof(struct foo))) == NULL) {
      for (; i >= 0; i--) {
	free(arr[i]); /* { dg-bogus "double-'free'" } */
      }
      free(arr); /* { dg-bogus "leak" "" { xfail *-*-* } } */
      return NULL;
    }
  }
  return arr;
}