]> git.saurik.com Git - redis.git/blobdiff - src/t_set.c
fixed a memory leak in the new Set code
[redis.git] / src / t_set.c
index 3fbf13a352affabf72ae6602e5194254d4fa752c..cb06a6a2e9ee43ba4189189da4107b341350ce83 100644 (file)
@@ -80,8 +80,8 @@ int setTypeIsMember(robj *subject, robj *value) {
     return 0;
 }
 
-setIterator *setTypeInitIterator(robj *subject) {
-    setIterator *si = zmalloc(sizeof(setIterator));
+setTypeIterator *setTypeInitIterator(robj *subject) {
+    setTypeIterator *si = zmalloc(sizeof(setTypeIterator));
     si->subject = subject;
     si->encoding = subject->encoding;
     if (si->encoding == REDIS_ENCODING_HT) {
@@ -94,7 +94,7 @@ setIterator *setTypeInitIterator(robj *subject) {
     return si;
 }
 
-void setTypeReleaseIterator(setIterator *si) {
+void setTypeReleaseIterator(setTypeIterator *si) {
     if (si->encoding == REDIS_ENCODING_HT)
         dictReleaseIterator(si->di);
     zfree(si);
@@ -103,7 +103,7 @@ void setTypeReleaseIterator(setIterator *si) {
 /* Move to the next entry in the set. Returns the object at the current
  * position, or NULL when the end is reached. This object will have its
  * refcount incremented, so the caller needs to take care of this. */
-robj *setTypeNext(setIterator *si) {
+robj *setTypeNext(setTypeIterator *si) {
     robj *ret = NULL;
     if (si->encoding == REDIS_ENCODING_HT) {
         dictEntry *de = dictNext(si->di);
@@ -151,7 +151,7 @@ unsigned long setTypeSize(robj *subject) {
  * to a hashtable) is presized to hold the number of elements in the original
  * set. */
 void setTypeConvert(robj *subject, int enc) {
-    setIterator *si;
+    setTypeIterator *si;
     robj *element;
     redisAssert(subject->type == REDIS_SET);
 
@@ -188,6 +188,7 @@ void saddCommand(redisClient *c) {
         }
     }
     if (setTypeAdd(set,c->argv[2])) {
+        touchWatchedKey(c->db,c->argv[1]);
         server.dirty++;
         addReply(c,shared.cone);
     } else {
@@ -203,6 +204,7 @@ void sremCommand(redisClient *c) {
 
     if (setTypeRemove(set,c->argv[2])) {
         if (setTypeSize(set) == 0) dbDelete(c->db,c->argv[1]);
+        touchWatchedKey(c->db,c->argv[1]);
         server.dirty++;
         addReply(c,shared.cone);
     } else {
@@ -241,6 +243,8 @@ void smoveCommand(redisClient *c) {
 
     /* Remove the src set from the database when empty */
     if (setTypeSize(srcset) == 0) dbDelete(c->db,c->argv[1]);
+    touchWatchedKey(c->db,c->argv[1]);
+    touchWatchedKey(c->db,c->argv[2]);
     server.dirty++;
 
     /* Create the destination set when it doesn't exist */
@@ -289,6 +293,7 @@ void spopCommand(redisClient *c) {
         addReplyBulk(c,ele);
         decrRefCount(ele);
         if (setTypeSize(set) == 0) dbDelete(c->db,c->argv[1]);
+        touchWatchedKey(c->db,c->argv[1]);
         server.dirty++;
     }
 }
@@ -314,7 +319,7 @@ int qsortCompareSetsByCardinality(const void *s1, const void *s2) {
 
 void sinterGenericCommand(redisClient *c, robj **setkeys, unsigned long setnum, robj *dstkey) {
     robj **sets = zmalloc(sizeof(robj*)*setnum);
-    setIterator *si;
+    setTypeIterator *si;
     robj *ele, *lenobj = NULL, *dstset = NULL;
     unsigned long j, cardinality = 0;
 
@@ -325,8 +330,10 @@ void sinterGenericCommand(redisClient *c, robj **setkeys, unsigned long setnum,
         if (!setobj) {
             zfree(sets);
             if (dstkey) {
-                if (dbDelete(c->db,dstkey))
+                if (dbDelete(c->db,dstkey)) {
+                    touchWatchedKey(c->db,dstkey);
                     server.dirty++;
+                }
                 addReply(c,shared.czero);
             } else {
                 addReply(c,shared.emptymultibulk);
@@ -390,6 +397,7 @@ void sinterGenericCommand(redisClient *c, robj **setkeys, unsigned long setnum,
             decrRefCount(dstset);
             addReply(c,shared.czero);
         }
+        touchWatchedKey(c->db,dstkey);
         server.dirty++;
     } else {
         lenobj->ptr = sdscatprintf(sdsempty(),"*%lu\r\n",cardinality);
@@ -411,7 +419,7 @@ void sinterstoreCommand(redisClient *c) {
 
 void sunionDiffGenericCommand(redisClient *c, robj **setkeys, int setnum, robj *dstkey, int op) {
     robj **sets = zmalloc(sizeof(robj*)*setnum);
-    setIterator *si;
+    setTypeIterator *si;
     robj *ele, *dstset = NULL;
     int j, cardinality = 0;
 
@@ -481,6 +489,7 @@ void sunionDiffGenericCommand(redisClient *c, robj **setkeys, int setnum, robj *
             decrRefCount(dstset);
             addReply(c,shared.czero);
         }
+        touchWatchedKey(c->db,dstkey);
         server.dirty++;
     }
     zfree(sets);