about summary refs log tree commit diff
path: root/src/libunixonacid/unixmessage_sender_free.c
blob: f01a9408c5624b4437132c2c5cb1bb977849a695 (plain) (blame)
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
/* ISC license. */

#include <sys/types.h>
#include <skalibs/disize.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/djbunix.h>
#include <skalibs/unixmessage.h>

void unixmessage_sender_free (unixmessage_sender *b)
{
  size_t n = genalloc_len(int, &b->fds) ;
  if (n)
  {
    size_t i = genalloc_s(disize, &b->offsets)[b->head].right ;
    for (; i < n ; i++)
    {
      int fd = genalloc_s(int, &b->fds)[i] ;
      if (fd < 0) (*b->closecb)(-(fd+1), b->closecbdata) ;
    }
  }
  genalloc_free(disize, &b->offsets) ;
  genalloc_free(int, &b->fds) ;
  stralloc_free(&b->data) ;
  *b = unixmessage_sender_zero ;
}