From cfaef8d5d494dc199117cb7a6841dfbdc43dd22e Mon Sep 17 00:00:00 2001 From: Dvir Volk Date: Tue, 17 May 2016 16:47:36 +0300 Subject: [PATCH] fixed bad transfer of ownership in HashSet causing a potential crash --- src/module.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/module.c b/src/module.c index e738678c..dab34a3d 100644 --- a/src/module.c +++ b/src/module.c @@ -1795,10 +1795,13 @@ int RM_HashSet(RedisModuleKey *key, int flags, ...) { if (flags & REDISMODULE_HASH_CFIELDS) low_flags |= HASH_SET_TAKE_FIELD; updated += hashTypeSet(key->value, field->ptr, value->ptr, low_flags); - field->ptr = NULL; /* Ownership is now of hashTypeSet() */ - - /* Cleanup */ - if (flags & REDISMODULE_HASH_CFIELDS) decrRefCount(field); + + /* If CFIELDS is active, ownership is now of hashTypeSet() */ + if (flags & REDISMODULE_HASH_CFIELDS) { + field->ptr = NULL; + /* Cleanup */ + decrRefCount(field); + } } va_end(ap); moduleDelKeyIfEmpty(key);