Browse Source

Don't reuse buffer pointer directly in read_socket_line

master
Con Kolivas 11 years ago
parent
commit
655be56b3d
  1. 6
      src/ckpool.c

6
src/ckpool.c

@ -150,6 +150,7 @@ int read_socket_line(connsock_t *cs, int timeout)
while (42) {
char readbuf[PAGESIZE] = {};
char *ptr;
FD_ZERO(&rd);
FD_SET(cs->fd, &rd);
@ -173,9 +174,10 @@ int read_socket_line(connsock_t *cs, int timeout)
}
buflen = cs->bufofs + ret + 1;
align_len(&buflen);
cs->buf = realloc(cs->buf, buflen);
if (unlikely(!cs->buf))
ptr = realloc(cs->buf, buflen);
if (unlikely(!ptr))
quit(1, "Failed to alloc buf of %d bytes in read_socket_line", (int)buflen);
cs->buf = ptr;
memcpy(cs->buf + cs->bufofs, readbuf, ret);
eom = strchr(cs->buf, '\n');
cs->bufofs += ret;

Loading…
Cancel
Save