aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/leak-pr105906.c
blob: 72901e4d1eb60391daeddf042a39d7132077ece3 (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
26
27
28
29
30
31
32
/* { dg-additional-options "-Wno-analyzer-too-complex" } */

#define NULL ((void *)0)

#define LEN 64

char **
epystr_explode(const char *delim, char *str)
{
	char **out = NULL;
	int i;

	if (str == NULL || delim == NULL)
		return NULL;

	out = __builtin_malloc(LEN * sizeof(char *));
	if (out == NULL)
		return NULL;

	for (i = 0; i < LEN; i++) {
		out[i] = __builtin_strdup("bla");
		if (out[i] == NULL) /* { dg-bogus "leak" } */
			goto freem;
	}
	return out;

freem:
	while (--i >= 0)
		__builtin_free(out[i]);
	__builtin_free(out);
	return NULL;
}