summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2016-06-23 16:12:07 +0200
committerGitHub <noreply@github.com>2016-06-23 16:12:07 +0200
commita66dd43331f278e000f222aa63e36922f14f3c21 (patch)
tree4e67882db2929a85be0df600ce7e89c2231a495b /src
parent393c4686ef1741c3a2c0e462655b80f607473ed4 (diff)
parente22f3e40d517b8eca10a0d02a5554987b1a22b77 (diff)
downloadredis-a66dd43331f278e000f222aa63e36922f14f3c21.tar.gz
Merge pull request #3331 from yossigo/fix_openkey_crash
Fix occasional RM_OpenKey() crashes.
Diffstat (limited to 'src')
-rw-r--r--src/module.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/module.c b/src/module.c
index 95c254a83..62efa373a 100644
--- a/src/module.c
+++ b/src/module.c
@@ -163,7 +163,8 @@ void RM_CloseKey(RedisModuleKey *key);
void autoMemoryCollect(RedisModuleCtx *ctx);
robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *flags, va_list ap);
void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx);
-void RM_ZsetRangeStop(RedisModuleKey *key);
+void RM_ZsetRangeStop(RedisModuleKey *kp);
+static void zsetKeyReset(RedisModuleKey *key);
/* --------------------------------------------------------------------------
* Heap allocation raw functions
@@ -1060,7 +1061,7 @@ void *RM_OpenKey(RedisModuleCtx *ctx, robj *keyname, int mode) {
kp->value = value;
kp->iter = NULL;
kp->mode = mode;
- RM_ZsetRangeStop(kp);
+ zsetKeyReset(kp);
autoMemoryAdd(ctx,REDISMODULE_AM_KEY,kp);
return (void*)kp;
}
@@ -1446,17 +1447,23 @@ int RM_ZsetScore(RedisModuleKey *key, RedisModuleString *ele, double *score) {
* Key API for Sorted Set iterator
* -------------------------------------------------------------------------- */
+static void zsetKeyReset(RedisModuleKey *key)
+{
+ key->ztype = REDISMODULE_ZSET_RANGE_NONE;
+ key->zcurrent = NULL;
+ key->zer = 1;
+}
+
/* Stop a sorted set iteration. */
void RM_ZsetRangeStop(RedisModuleKey *key) {
/* Free resources if needed. */
- if (key->ztype == REDISMODULE_ZSET_RANGE_LEX)
+ if (key->ztype == REDISMODULE_ZSET_RANGE_LEX) {
zslFreeLexRange(&key->zlrs);
+ }
/* Setup sensible values so that misused iteration API calls when an
* iterator is not active will result into something more sensible
* than crashing. */
- key->ztype = REDISMODULE_ZSET_RANGE_NONE;
- key->zcurrent = NULL;
- key->zer = 1;
+ zsetKeyReset(key);
}
/* Return the "End of range" flag value to signal the end of the iteration. */