From e3edae957b7c4d5f1194828bf342397bc9fa6515 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 18 May 2016 16:17:46 +0200 Subject: [PATCH] Modules: RM_HashSet() SDS ownership business clarified in comments. Related to #3239. --- src/module.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/module.c b/src/module.c index dab34a3d..6a8a5f5b 100644 --- a/src/module.c +++ b/src/module.c @@ -1788,18 +1788,18 @@ int RM_HashSet(RedisModuleKey *key, int flags, ...) { continue; } + int low_flags = HASH_SET_COPY; /* If CFIELDS is active, we can pass the ownership of the * SDS object to the low level function that sets the field * to avoid a useless copy. */ - int low_flags = HASH_SET_COPY; if (flags & REDISMODULE_HASH_CFIELDS) low_flags |= HASH_SET_TAKE_FIELD; updated += hashTypeSet(key->value, field->ptr, value->ptr, low_flags); - - /* If CFIELDS is active, ownership is now of hashTypeSet() */ + + /* If CFIELDS is active, SDS string ownership is now of hashTypeSet(), + * however we still have to release the 'field' object shell. */ if (flags & REDISMODULE_HASH_CFIELDS) { - field->ptr = NULL; - /* Cleanup */ + field->ptr = NULL; /* Prevent the SDS string from being freed. */ decrRefCount(field); } }