summaryrefslogtreecommitdiff
path: root/src/libunixonacid/unixmessage_receiver_free.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libunixonacid/unixmessage_receiver_free.c')
-rw-r--r--src/libunixonacid/unixmessage_receiver_free.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libunixonacid/unixmessage_receiver_free.c b/src/libunixonacid/unixmessage_receiver_free.c
index 353797b..74654d0 100644
--- a/src/libunixonacid/unixmessage_receiver_free.c
+++ b/src/libunixonacid/unixmessage_receiver_free.c
@@ -1,12 +1,29 @@
/* ISC license. */
#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
#include <skalibs/unixmessage.h>
void unixmessage_receiver_free (unixmessage_receiver_t *b)
{
+ register unsigned int h = b->maindata.len ;
b->fd = -1 ;
stralloc_free(&b->maindata) ;
+ h = h != b->mainlen || b->auxdata.len != b->auxlen || cbuffer_len(&b->auxb) ;
+ if (h)
+ {
+ register unsigned int n = b->auxdata.len / sizeof(int) ;
+ while (n--) fd_close(((int *)b->auxdata.s)[n]) ;
+ }
stralloc_free(&b->auxdata) ;
- b->mainlen = b->auxlen = 0 ;
+ if (h)
+ {
+ register unsigned int n = cbuffer_len(&b->auxb) / sizeof(int) ;
+ if (n)
+ {
+ int fds[n] ;
+ cbuffer_get(&b->auxb, (char *)fds, n * sizeof(int)) ;
+ while (n--) fd_close(fds[n]) ;
+ }
+ }
}