1  #include <stdio.h>
       2  
       3  struct foo {
       4    FILE *file;
       5  };
       6  
       7  extern void unknown_fn ();
       8  extern void unknown_fn2 (const struct foo *f);
       9  
      10  int test_1 (struct foo *p)
      11  {
      12    if ((p->file = fopen("test.txt", "w")) == NULL)
      13      return 1;
      14    unknown_fn ();
      15    return 0; /* { dg-bogus "leak" } */
      16  }
      17  
      18  int test_2 (struct foo *p)
      19  {
      20    if ((p->file = fopen("test.txt", "w")) == NULL)
      21      return 1;
      22    return 0; /* { dg-bogus "leak" } */
      23  }
      24  
      25  int test_3 (void)
      26  {
      27    struct foo f;
      28    struct foo *p = &f;
      29    if ((p->file = fopen("test.txt", "w")) == NULL)
      30      return 1;
      31    unknown_fn ();
      32    return 0;
      33  } /* { dg-warning "leak" } */
      34  
      35  int test_4 (void)
      36  {
      37    struct foo f;
      38    struct foo *p = &f;
      39    if ((p->file = fopen("test.txt", "w")) == NULL)
      40      return 1;
      41    return 0;
      42  } /* { dg-warning "leak" } */
      43  
      44  int test_5 (void)
      45  {
      46    struct foo f;
      47    struct foo *p = &f;
      48    if ((p->file = fopen("test.txt", "w")) == NULL)
      49      return 1;
      50    /* Although p is const, the underlying FILE * is not and could be closed.  */
      51    unknown_fn2 (p);
      52    return 0; /* { dg-bogus "leak" } */
      53  }