From 4eed1715c34141eac6516cd178e1738c0c5871ac Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 17 Jan 2016 08:03:09 +1100 Subject: [PATCH] Fix logic fail --- src/ckpool.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 889414cc..12d07465 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -534,13 +534,14 @@ static void add_buflen(connsock_t *cs, const char *readbuf, const int len) { int backoff = 1; int buflen; - char *newbuf; buflen = round_up_page(cs->bufofs + len + 1); while (cs->bufsize < buflen) { - newbuf = realloc(cs->buf, buflen); + char *newbuf = realloc(cs->buf, buflen); + if (likely(newbuf)) { cs->bufsize = buflen; + cs->buf = newbuf; break; } if (backoff == 1) @@ -548,9 +549,6 @@ static void add_buflen(connsock_t *cs, const char *readbuf, const int len) cksleep_ms(backoff); backoff <<= 1; } - cs->buf = newbuf; - if (unlikely(!cs->buf)) - quit(1, "Failed to alloc buf of %d bytes in read_socket_line", (int)buflen); memcpy(cs->buf + cs->bufofs, readbuf, len); cs->bufofs += len; cs->buf[cs->bufofs] = '\0';