mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
SRANDMEMBER <count> leak fixed.
For "CASE 4" (see code) we need to free the element if it's already in the result dictionary and adding it failed.
This commit is contained in:
parent
be90c803e3
commit
578c94597f
18
src/t_set.c
18
src/t_set.c
@ -476,19 +476,21 @@ void srandmemberWithCountCommand(redisClient *c) {
|
|||||||
unsigned long added = 0;
|
unsigned long added = 0;
|
||||||
|
|
||||||
while(added < count) {
|
while(added < count) {
|
||||||
int retval;
|
|
||||||
|
|
||||||
encoding = setTypeRandomElement(set,&ele,&llele);
|
encoding = setTypeRandomElement(set,&ele,&llele);
|
||||||
if (encoding == REDIS_ENCODING_INTSET) {
|
if (encoding == REDIS_ENCODING_INTSET) {
|
||||||
retval = dictAdd(d,createStringObjectFromLongLong(llele),NULL);
|
ele = createStringObjectFromLongLong(llele);
|
||||||
} else if (ele->encoding == REDIS_ENCODING_RAW) {
|
} else if (ele->encoding == REDIS_ENCODING_RAW) {
|
||||||
retval = dictAdd(d,dupStringObject(ele),NULL);
|
ele = dupStringObject(ele);
|
||||||
} else if (ele->encoding == REDIS_ENCODING_INT) {
|
} else if (ele->encoding == REDIS_ENCODING_INT) {
|
||||||
retval = dictAdd(d,
|
ele = createStringObjectFromLongLong((long)ele->ptr);
|
||||||
createStringObjectFromLongLong((long)ele->ptr),NULL);
|
|
||||||
}
|
}
|
||||||
|
/* Try to add the object to the dictionary. If it already exists
|
||||||
if (retval == DICT_OK) added++;
|
* free it, otherwise increment the number of objects we have
|
||||||
|
* in the result dictionary. */
|
||||||
|
if (dictAdd(d,ele,NULL) == DICT_OK)
|
||||||
|
added++;
|
||||||
|
else
|
||||||
|
decrRefCount(ele);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user