zunionInterDiffGenericCommand use ztrycalloc to avoid OOM panic (#13052)
In low memory situations, sending a big number of arguments (sets) may cause OOM panic. Use ztrycalloc, like we do on LCS and XAUTOCLAIM, and fail gracefully. This change affects the following commands: ZUNION, ZINTER, ZDIFF, ZUNIONSTORE, ZINTERSTORE, ZDIFFSTORE, ZINTERCARD.
This commit is contained in:
parent
32f44da510
commit
063de675e0
@ -2663,8 +2663,14 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in
|
||||
return;
|
||||
}
|
||||
|
||||
/* Try to allocate the src table, and abort on insufficient memory. */
|
||||
src = ztrycalloc(sizeof(zsetopsrc) * setnum);
|
||||
if (src == NULL) {
|
||||
addReplyError(c, "Insufficient memory, failed allocating transient memory, too many args.");
|
||||
return;
|
||||
}
|
||||
|
||||
/* read keys to be used for input */
|
||||
src = zcalloc(sizeof(zsetopsrc) * setnum);
|
||||
for (i = 0, j = numkeysIndex+1; i < setnum; i++, j++) {
|
||||
robj *obj = lookupKeyRead(c->db, c->argv[j]);
|
||||
if (obj != NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user