dictEntry *de;
} hashIterator;
-static void hashInitIterator(robj *subject, hashIterator *hi) {
+static hashIterator *hashInitIterator(robj *subject) {
+ hashIterator *hi = zmalloc(sizeof(hashIterator));
hi->encoding = subject->encoding;
if (hi->encoding == REDIS_ENCODING_ZIPMAP) {
hi->zi = zipmapRewind(subject->ptr);
} else {
redisAssert(NULL);
}
+ return hi;
}
static void hashReleaseIterator(hashIterator *hi) {
if (hi->encoding == REDIS_ENCODING_HT) {
dictReleaseIterator(hi->di);
}
+ zfree(hi);
}
/* Move to the next entry in the hash. Return REDIS_OK when the next entry
static void genericHgetallCommand(redisClient *c, int flags) {
robj *o, *lenobj, *obj;
unsigned long count = 0;
- hashIterator hi;
+ hashIterator *hi;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptymultibulk)) == NULL
|| checkType(c,o,REDIS_HASH)) return;
addReply(c,lenobj);
decrRefCount(lenobj);
- hashInitIterator(o, &hi);
- while (hashNext(&hi) != REDIS_ERR) {
+ hi = hashInitIterator(o);
+ while (hashNext(hi) != REDIS_ERR) {
if (flags & REDIS_HASH_KEY) {
- obj = hashCurrent(&hi,REDIS_HASH_KEY);
+ obj = hashCurrent(hi,REDIS_HASH_KEY);
addReplyBulk(c,obj);
count++;
}
if (flags & REDIS_HASH_VALUE) {
- obj = hashCurrent(&hi,REDIS_HASH_VALUE);
+ obj = hashCurrent(hi,REDIS_HASH_VALUE);
addReplyBulk(c,obj);
count++;
}
}
- hashReleaseIterator(&hi);
+ hashReleaseIterator(hi);
lenobj->ptr = sdscatprintf(sdsempty(),"*%lu\r\n",count);
}