summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-07-11 15:49:09 +0200
committerantirez <antirez@gmail.com>2017-07-11 15:49:09 +0200
commite1b8b4b6daea28129bf038abc96707ef1a7d220e (patch)
tree4088de090a61a1e85f18012043c56efdab373481
parent5bd46d33db53186fddefbe2be8ab8a2805a66612 (diff)
downloadredis-e1b8b4b6daea28129bf038abc96707ef1a7d220e.tar.gz
CLUSTER GETKEYSINSLOT: avoid overallocating.
Close #3911.
-rw-r--r--src/cluster.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 407ddee82..a516e911f 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -4380,6 +4380,11 @@ void clusterCommand(client *c) {
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);
numkeys = getKeysInSlot(slot, keys, maxkeys);
addReplyMultiBulkLen(c,numkeys);