From 98aec22e096f51d73ccb3fc697e6b38343172421 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 9 Jun 2014 21:16:45 +1000 Subject: [PATCH] Close clean shut down sockets in read_socket_line and invalidate the fd --- src/ckpool.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ckpool.c b/src/ckpool.c index a5fbfb6e..3a745771 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -165,6 +165,7 @@ int read_socket_line(connsock_t *cs, int timeout) ret = recv(cs->fd, readbuf, PAGESIZE - 4, 0); if (ret < 1) { LOGERR("Failed to recv in read_socket_line"); + ret = -1; goto out; } buflen = cs->bufofs + ret + 1; @@ -184,8 +185,13 @@ int read_socket_line(connsock_t *cs, int timeout) cs->buflen = cs->bufofs = 0; eom[0] = '\0'; out: - if (ret < 1) + if (ret < 1) { dealloc(cs->buf); + if (ret < 0 && cs->fd > 0) { + close(cs->fd); + cs->fd = -1; + } + } return ret; }