]> git.saurik.com Git - redis.git/commitdiff
Fix bug where the client is not present in server.clients when free'ing it
authorPieter Noordhuis <pcnoordhuis@gmail.com>
Mon, 6 Sep 2010 09:27:22 +0000 (11:27 +0200)
committerPieter Noordhuis <pcnoordhuis@gmail.com>
Tue, 7 Sep 2010 08:25:34 +0000 (10:25 +0200)
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. Port of 00a90feb.

src/networking.c

index a39be7c4ea8b81ead00a145cdc7a2dcec516d9c7..104444f090545a1f56166a9dd8c852be8bd51b19 100644 (file)
@@ -17,6 +17,14 @@ 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();
@@ -43,11 +51,6 @@ 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;