Commit e1b8b4b6 authored by antirez's avatar antirez
Browse files

CLUSTER GETKEYSINSLOT: avoid overallocating.

Close #3911.
parent 5bd46d33
...@@ -4380,6 +4380,11 @@ void clusterCommand(client *c) { ...@@ -4380,6 +4380,11 @@ void clusterCommand(client *c) {
return; return;
} }
/* Avoid allocating more than needed in case of large COUNT argument
* and smaller actual number of keys. */
unsigned int keys_in_slot = countKeysInSlot(slot);
if (maxkeys > keys_in_slot) maxkeys = keys_in_slot;
keys = zmalloc(sizeof(robj*)*maxkeys); keys = zmalloc(sizeof(robj*)*maxkeys);
numkeys = getKeysInSlot(slot, keys, maxkeys); numkeys = getKeysInSlot(slot, keys, maxkeys);
addReplyMultiBulkLen(c,numkeys); addReplyMultiBulkLen(c,numkeys);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment