summaryrefslogtreecommitdiff
path: root/src/libunixonacid/unixmessage_sender_free.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-10 16:12:57 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-10 16:12:57 +0000
commit1a83aaeb67d50f321fbf4caf0d402bbacebd6857 (patch)
treeeff182292253f5ab9e1d2de49669c8629fc2eab5 /src/libunixonacid/unixmessage_sender_free.c
parent00a4c6056dba93c98cac687f24d5122acc76ded0 (diff)
downloadskalibs-1a83aaeb67d50f321fbf4caf0d402bbacebd6857.tar.xz
Bugfix: unixmessage_sender_free didn't close all the pending fds
Diffstat (limited to 'src/libunixonacid/unixmessage_sender_free.c')
-rw-r--r--src/libunixonacid/unixmessage_sender_free.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/libunixonacid/unixmessage_sender_free.c b/src/libunixonacid/unixmessage_sender_free.c
index 797220c..965b1a7 100644
--- a/src/libunixonacid/unixmessage_sender_free.c
+++ b/src/libunixonacid/unixmessage_sender_free.c
@@ -4,24 +4,21 @@
#include <skalibs/diuint.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+#include <skalibs/djbunix.h>
#include <skalibs/unixmessage.h>
void unixmessage_sender_free (unixmessage_sender_t *b)
{
-#ifdef SKALIBS_HASANCILAUTOCLOSE
+ unsigned int i = genalloc_s(diuint, &b->offsets)[b->head].right ;
+ unsigned int n = genalloc_len(int, &b->fds) ;
+ for (; i < n ; i++)
{
- diuint *offsets = genalloc_s(unsigned int, &b->offsets) ;
- unsigned int n = genalloc_len(unsigned int, &b->offsets) ;
- int *fds = genalloc_s(int, &b->fds) ;
- unsigned int nfds = genalloc_len(int, &b->fds) ;
- for (; b->head < n ; b->head++)
- {
- register unsigned int last = b->head+1 < n ? offsets[b->head+1].right : nfds ;
- register unsigned int i = offsets[b->head].right ;
- for (; i < last ; i++) if (fds[i] >= 0) fd_close(fds[i]) ;
- }
- }
+ register int fd = genalloc_s(int, &b->fds)[i] ;
+ if (fd < 0) fd_close(-(fd+1)) ;
+#ifdef SKALIBS_HASANCILAUTOCLOSE
+ else fd_close(fd) ;
#endif
+ }
genalloc_free(diuint, &b->offsets) ;
genalloc_free(int, &b->fds) ;
stralloc_free(&b->data) ;