Index: memcached.c =================================================================== --- memcached.c (revision 497) +++ memcached.c (working copy) @@ -467,10 +467,12 @@ static void conn_shrink(conn *c) { return; if (c->rsize > READ_BUFFER_HIGHWAT && c->rbytes < DATA_BUFFER_SIZE) { + char *newbuf; + if (c->rcurr != c->rbuf) memmove(c->rbuf, c->rcurr, (size_t)c->rbytes); - char *newbuf = (char *)realloc((void *)c->rbuf, DATA_BUFFER_SIZE); + newbuf = (char *)realloc((void *)c->rbuf, DATA_BUFFER_SIZE); if (newbuf) { c->rbuf = newbuf; @@ -653,7 +655,7 @@ static int build_udp_headers(conn *c) { static void out_string(conn *c, const char *str) { - int len; + size_t len; assert(c != NULL); @@ -667,8 +669,8 @@ static void out_string(conn *c, const ch len = strlen(str); } - strcpy(c->wbuf, str); - strcpy(c->wbuf + len, "\r\n"); + memcpy(c->wbuf, str, len); + memcpy(c->wbuf + len, "\r\n", 2); c->wbytes = len + 2; c->wcurr = c->wbuf; @@ -1689,7 +1691,6 @@ void accept_new_conns(const bool do_acce * TRANSMIT_HARD_ERROR Can't write (c->state is set to conn_closing) */ static int transmit(conn *c) { - int res; assert(c != NULL); @@ -1699,7 +1700,9 @@ static int transmit(conn *c) { c->msgcurr++; } if (c->msgcurr < c->msgused) { + ssize_t res; struct msghdr *m = &c->msglist[c->msgcurr]; + res = sendmsg(c->sfd, m, 0); if (res > 0) { stats.bytes_written += res; @@ -1754,6 +1757,7 @@ static void drive_machine(conn *c) { assert(c != NULL); while (!stop) { + conn *newc = NULL; switch(c->state) { case conn_listening: addrlen = sizeof(addr); @@ -1776,7 +1780,7 @@ static void drive_machine(conn *c) { close(sfd); break; } - conn *newc = conn_new(sfd, conn_read, EV_READ | EV_PERSIST, + newc = conn_new(sfd, conn_read, EV_READ | EV_PERSIST, DATA_BUFFER_SIZE, false); if (!newc) { if (settings.verbose > 0) @@ -2095,7 +2099,7 @@ static int new_socket_unix(void) { return sfd; } -static int server_socket_unix(char *path) { +static int server_socket_unix(const char *path) { int sfd; struct linger ling = {0, 0}; struct sockaddr_un addr;