From bee51ef883b2e328cc4a4f666c4f66da641d0bbb Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 27 Apr 2020 22:40:15 +0200 Subject: [PATCH] Rework comment in dictEncObjKeyCompare(). --- src/server.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/server.c b/src/server.c index 1bfca1a0b..1086dab48 100644 --- a/src/server.c +++ b/src/server.c @@ -1219,16 +1219,15 @@ int dictEncObjKeyCompare(void *privdata, const void *key1, o2->encoding == OBJ_ENCODING_INT) return o1->ptr == o2->ptr; - /* due to OBJ_STATIC_REFCOUNT, we rather not call sdsEncodedObject unnecessarily */ - if (!sdsEncodedObject(o1)) - o1 = getDecodedObject(o1); - if (!sdsEncodedObject(o2)) - o2 = getDecodedObject(o2); + /* Due to OBJ_STATIC_REFCOUNT, we avoid calling getDecodedObject() without + * good reasons, because it would incrRefCount() the object, which + * is invalid. So we check to make sure dictFind() works with static + * objects as well. */ + if (!sdsEncodedObject(o1)) o1 = getDecodedObject(o1); + if (!sdsEncodedObject(o2)) o2 = getDecodedObject(o2); cmp = dictSdsKeyCompare(privdata,o1->ptr,o2->ptr); - if (o1!=key1) - decrRefCount(o1); - if (o2!=key2) - decrRefCount(o2); + if (o1!=key1) decrRefCount(o1); + if (o2!=key2) decrRefCount(o2); return cmp; }