Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/data-model-20a.c

raw
1 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
2
3 #include <stdlib.h>
4
5 struct foo { int dummy; };
6
7 struct foo **
8 test (int n) {
9 struct foo **arr;
10 int i;
11
12 if ((arr = (struct foo **)malloc(n * sizeof(struct foo *))) == NULL)
13 return NULL;
14
15 for (i = 0; i < n; i++) {
16 if ((arr[i] = (struct foo *)malloc(sizeof(struct foo))) == NULL) {
17 for (; i >= 0; i--) {
18 free(arr[i]); /* { dg-bogus "double-'free'" } */
19 }
20 free(arr); /* { dg-bogus "leak" "" { xfail *-*-* } } */
21 return NULL;
22 }
23 }
24 return arr;
25 }