allow dictFind using static robj

since the recent addition of OBJ_STATIC_REFCOUNT and the assertion in
incrRefCount it is now impossible to use dictFind using a static robj,
because dictEncObjKeyCompare will call getDecodedObject which tries to
increment the refcount just in order to decrement it later.
This commit is contained in:
Oran Agra 2020-04-27 23:17:19 +03:00 committed by antirez
parent e853b8f137
commit d92f14e825

View File

@ -1219,10 +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);
cmp = dictSdsKeyCompare(privdata,o1->ptr,o2->ptr);
if (o1!=key1)
decrRefCount(o1);
if (o2!=key2)
decrRefCount(o2);
return cmp;
}