Commit 00a90feb authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Fix bug where the client is not present in server.clients when free'ing it

When creating the readable event results in an error (this happens when
the server hits OS limits), the client was not added to the list of
clients when freeClient was called. This results in an assertion error.
It is better to check this condition first and free the client
immediately when this condition occurs.
parent aaed0894
...@@ -2717,6 +2717,14 @@ static redisClient *createClient(int fd) { ...@@ -2717,6 +2717,14 @@ static redisClient *createClient(int fd) {
anetNonBlock(NULL,fd); anetNonBlock(NULL,fd);
anetTcpNoDelay(NULL,fd); anetTcpNoDelay(NULL,fd);
if (!c) return NULL; if (!c) return NULL;
if (aeCreateFileEvent(server.el,fd,AE_READABLE,
readQueryFromClient, c) == AE_ERR)
{
close(fd);
zfree(c);
return NULL;
}
selectDb(c,0); selectDb(c,0);
c->fd = fd; c->fd = fd;
c->querybuf = sdsempty(); c->querybuf = sdsempty();
...@@ -2742,11 +2750,6 @@ static redisClient *createClient(int fd) { ...@@ -2742,11 +2750,6 @@ static redisClient *createClient(int fd) {
c->pubsub_patterns = listCreate(); c->pubsub_patterns = listCreate();
listSetFreeMethod(c->pubsub_patterns,decrRefCount); listSetFreeMethod(c->pubsub_patterns,decrRefCount);
listSetMatchMethod(c->pubsub_patterns,listMatchObjects); listSetMatchMethod(c->pubsub_patterns,listMatchObjects);
if (aeCreateFileEvent(server.el, c->fd, AE_READABLE,
readQueryFromClient, c) == AE_ERR) {
freeClient(c);
return NULL;
}
listAddNodeTail(server.clients,c); listAddNodeTail(server.clients,c);
initClientMultiState(c); initClientMultiState(c);
return c; return c;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment