summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-09-06 11:23:07 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-09-07 10:24:50 +0200
commit00a90feb0b3dabfab683875ae7d907f1e39cd80e (patch)
treea0a67c4cce9c156232c2190ae81309ad5467498c
parentaaed0894cc7c04dc215ba82083fc4cc359e66701 (diff)
downloadredis-00a90feb0b3dabfab683875ae7d907f1e39cd80e.tar.gz
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.
-rw-r--r--redis.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/redis.c b/redis.c
index 351de908b..bdc23af14 100644
--- a/redis.c
+++ b/redis.c
@@ -2717,6 +2717,14 @@ static redisClient *createClient(int fd) {
anetNonBlock(NULL,fd);
anetTcpNoDelay(NULL,fd);
if (!c) return NULL;
+ if (aeCreateFileEvent(server.el,fd,AE_READABLE,
+ readQueryFromClient, c) == AE_ERR)
+ {
+ close(fd);
+ zfree(c);
+ return NULL;
+ }
+
selectDb(c,0);
c->fd = fd;
c->querybuf = sdsempty();
@@ -2742,11 +2750,6 @@ static redisClient *createClient(int fd) {
c->pubsub_patterns = listCreate();
listSetFreeMethod(c->pubsub_patterns,decrRefCount);
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);
initClientMultiState(c);
return c;