From b753e6cf1848c1fde61f10d83ffbcb11de4a51ca Mon Sep 17 00:00:00 2001 From: Codewalker Date: Wed, 24 Dec 2014 12:04:39 -0600 Subject: [PATCH] Fix a bug where select() could fail due to negative max socket fd. Connection objects in the disconnected state should not have their fd taken into account when determining the maximum socket fd number, as they are not set in the bitmask with FD_SET, and their fd could be anything, even a wildly large or small number. --- src/event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/event.c b/src/event.c index 32a4898..1d6fd4c 100644 --- a/src/event.c +++ b/src/event.c @@ -218,7 +218,8 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout) tls_read_bytes += tls_pending(conn->tls); } - if (conn->sock > max) max = conn->sock; + if (conn->state != XMPP_STATE_DISCONNECTED && conn->sock > max) + max = conn->sock; connitem = connitem->next; }