From e542132b07a76c73cd5e1dd067671afbb4c53fe6 Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Mon, 4 Nov 2019 20:32:19 +0800 Subject: expires: refactoring judgment about whether a key is expired Calling lookupKey*() many times to search a key in one command may get different result. That's because lookupKey*() calls expireIfNeeded(), and delete the key when reach the expire time. So we can get an robj before the expire time, but a NULL after the expire time. The worst is that may lead to Redis crash, for example `RPOPLPUSH foo foo` the first time we get a list form `foo` and hold the pointer, but when we get `foo` again it's expired and deleted. Now we hold a freed memory, when execute rpoplpushHandlePush() redis crash. To fix it, we can refactor the judgment about whether a key is expired, using the same basetime `server.cmd_start_mstime` instead of calling mstime() everytime. --- src/server.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/server.c') diff --git a/src/server.c b/src/server.c index 8f165113d..99438ccac 100644 --- a/src/server.c +++ b/src/server.c @@ -3596,6 +3596,7 @@ int processCommand(client *c) { queueMultiCommand(c); addReply(c,shared.queued); } else { + server.cmd_start_mstime = mstime(); call(c,CMD_CALL_FULL); c->woff = server.master_repl_offset; if (listLength(server.ready_keys)) -- cgit v1.2.1