From 84d21ff8c24ba8062043b2bc9ce44e4affef083f Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Wed, 5 Sep 2012 00:50:42 +0200 Subject: [PATCH] properly count file descriptors --- sndiod/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sndiod/file.c b/sndiod/file.c index 2e7c9ca..1d175c4 100644 --- a/sndiod/file.c +++ b/sndiod/file.c @@ -221,8 +221,7 @@ file_new(struct fileops *ops, void *arg, char *name, unsigned int nfds) { struct file *f; - file_nfds += nfds; - if (file_nfds > MAXFDS) { + if (file_nfds + nfds > MAXFDS) { #ifdef DEBUG if (log_level >= 1) { log_puts(name); @@ -232,6 +231,7 @@ file_new(struct fileops *ops, void *arg, char *name, unsigned int nfds) return NULL; } f = xmalloc(sizeof(struct file)); + f->nfds = nfds; f->ops = ops; f->arg = arg; f->name = name; @@ -244,6 +244,7 @@ file_new(struct fileops *ops, void *arg, char *name, unsigned int nfds) log_puts(": created\n"); } #endif + file_nfds += f->nfds; return f; } @@ -256,6 +257,7 @@ file_del(struct file *f) panic(); } #endif + file_nfds -= f->nfds; f->state = FILE_ZOMB; #ifdef DEBUG if (log_level >= 3) {