Skip to content

Commit

Permalink
CLUSTER GETKEYSINSLOT: avoid overallocating.
Browse files Browse the repository at this point in the history
Close #3911.
  • Loading branch information
antirez committed Jul 11, 2017
1 parent 5bd46d3 commit e1b8b4b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cluster.c
Expand Up @@ -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);
Expand Down

0 comments on commit e1b8b4b

Please sign in to comment.