blob: e5d27a4a33a697f87b4839857490b87cf1accfd8 (
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
33
34
35
36
|
#include <stdlib.h>
extern int foo (void);
int successes;
int failures;
#define ONE_DIAMOND \
do { \
void *ptr = malloc (128); \
if (foo ()) \
successes++; \
else \
failures++; \
free (ptr); \
} while (0)
#define TEN_DIAMONDS \
do { \
ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; \
ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; \
} while (0)
void test_3 (void *ptr)
{
free (ptr);
#if 1
ONE_DIAMOND;
#else
/* TODO: enabling this leads to numerous duplicated reports,
all of them detailing all the extraneous info about the malloc/free
within the diamonds. */
TEN_DIAMONDS;
#endif
free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
}
|