From: antirez <antirez@gmail.com>
Date: Mon, 29 Mar 2010 10:23:02 +0000 (+0200)
Subject: Fixed a refcount stuff leading to PUBSUB crashes
X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/201037f56215626ed2c96bdc589f486411b146d6

Fixed a refcount stuff leading to PUBSUB crashes
---

diff --git a/redis.c b/redis.c
index 453ab531..6e450aaf 100644
--- a/redis.c
+++ b/redis.c
@@ -9301,6 +9301,8 @@ static int pubsubUnsubscribe(redisClient *c, robj *class, int notify) {
     int retval = 0;
 
     /* Remove the class from the client -> classes hash table */
+    incrRefCount(class); /* class may be just a pointer to the same object
+                            we have in the hash tables. Protect it... */
     if (dictDelete(c->pubsub_classes,class) == DICT_OK) {
         retval = 1;
         /* Remove the client from the class -> clients list hash table */
@@ -9318,6 +9320,7 @@ static int pubsubUnsubscribe(redisClient *c, robj *class, int notify) {
         addReplyBulk(c,class);
         addReplyLong(c,dictSize(c->pubsub_classes));
     }
+    decrRefCount(class); /* it is finally safe to release it */
     return retval;
 }