1  #include <stdlib.h>
       2  
       3  extern int foo (void);
       4  
       5  int successes;
       6  int failures;
       7  
       8  #define ONE_DIAMOND \
       9      do {                                                \
      10        void *ptr = malloc (128);				\
      11        if (foo ())					\
      12  	successes++;					\
      13        else						\
      14  	failures++;					\
      15        free (ptr);					\
      16      } while (0)
      17  
      18  #define TEN_DIAMONDS \
      19    do {								   \
      20      ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND;	\
      21      ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; ONE_DIAMOND; \
      22   } while (0)
      23  
      24  void test_3 (void *ptr)
      25  {
      26    free (ptr);
      27  #if 1
      28    ONE_DIAMOND;
      29  #else
      30    /* TODO: enabling this leads to numerous duplicated reports,
      31       all of them detailing all the extraneous info about the malloc/free
      32       within the diamonds.  */
      33    TEN_DIAMONDS;
      34  #endif
      35    free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
      36  }