1  /* { dg-additional-options "-Wno-analyzer-fd-leak" } */
       2  // TODO: remove need for this option
       3  
       4  typedef __SIZE_TYPE__ size_t;
       5  #define NULL ((void *)0)
       6  #define POLLIN 0x001
       7  
       8  typedef struct {
       9    unsigned long int __val[(1024 / (8 * sizeof(unsigned long int)))];
      10  } __sigset_t;
      11  
      12  typedef unsigned int socklen_t;
      13  
      14  struct timespec {
      15    /* [...snip...] */
      16  };
      17  
      18  typedef unsigned long int nfds_t;
      19  
      20  struct pollfd {
      21    int fd;
      22    short int events;
      23    short int revents;
      24  };
      25  
      26  extern int ppoll(struct pollfd *__fds, nfds_t __nfds,
      27                   const struct timespec *__timeout, const __sigset_t *__ss);
      28  
      29  struct sockaddr_un {
      30    /* [...snip...] */
      31    char sun_path[108];
      32  };
      33  
      34  typedef union {
      35    /* [...snip...] */
      36    struct sockaddr_un *__restrict __sockaddr_un__;
      37    /* [...snip...] */
      38  } __SOCKADDR_ARG __attribute__((transparent_union));
      39  
      40  extern int accept(int __fd, __SOCKADDR_ARG __addr,
      41                    socklen_t *__restrict __addr_len);
      42  
      43  extern void *calloc(size_t __nmemb, size_t __size)
      44    __attribute__((__nothrow__, __leaf__))
      45    __attribute__((__malloc__))
      46    __attribute__((__alloc_size__(1, 2)));
      47  
      48  extern void *realloc(void *__ptr, size_t __size)
      49    __attribute__((__nothrow__, __leaf__))
      50    __attribute__((__warn_unused_result__))
      51    __attribute__((__alloc_size__(2)));
      52  
      53  extern void exit(int __status)
      54    __attribute__((__nothrow__, __leaf__))
      55    __attribute__((__noreturn__));
      56  
      57  int main() {
      58    int rc;
      59    int nsockets = 1;
      60    struct pollfd *pollfds, *newpollfds;
      61    struct sockaddr_un remote;
      62    socklen_t len = sizeof(remote);
      63  
      64    pollfds = calloc(1, sizeof(struct pollfd));
      65    if (!pollfds) {
      66      exit(1);
      67    }
      68  
      69    rc = ppoll(pollfds, nsockets, NULL, NULL);
      70    if (rc < 0) {
      71      exit(2);
      72    }
      73  
      74    nsockets++;
      75    newpollfds = realloc(pollfds, nsockets * sizeof(*pollfds));
      76    if (!newpollfds) {
      77      exit(3);
      78    }
      79    pollfds = newpollfds;
      80    pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
      81    exit(4);
      82  }