summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-08-31 11:08:53 +0200
committerantirez <antirez@gmail.com>2012-08-31 11:08:53 +0200
commit42a239b8887a2f840f4207a43c8277d48df08daf (patch)
treefb00b931a1bb1616dadbec64c07f27f7694a65de
parent851ac9d072a0a95e93b4e0949da95bd72abe8056 (diff)
downloadredis-42a239b8887a2f840f4207a43c8277d48df08daf.tar.gz
Scripting: Reset Lua fake client reply_bytes after command execution.
Lua scripting uses a fake client in order to run commands in the context of a client, accumulate the reply, and convert it into a Lua object to return to the caller. This client is reused again and again, and is referenced by the server.lua_client globally accessible pointer. However after every call to redis.call() or redis.pcall(), that is handled by the luaRedisGenericCommand() function, the reply_bytes field of the client was not set back to zero. This filed is used to estimate the amount of memory currently used in the reply. Because of the lack of reset, script after script executed, this value used to get bigger and bigger, and in the end on 32 bit systems it triggered the following assert: redisAssert(c->reply_bytes < ULONG_MAX-(1024*64)); On 64 bit systems this does not happen because it takes too much time to reach values near to 2^64 for users to see the practical effect of the bug. Now in the cleanup stage of luaRedisGenericCommand() we reset the reply_bytes counter to zero, avoiding the issue. It is not practical to add a test for this bug, but the fix was manually tested using a debugger. This commit fixes issue #656.
-rw-r--r--src/scripting.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/scripting.c b/src/scripting.c
index b1cbc6ff4..be52a1141 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -287,6 +287,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
luaSortArray(lua);
}
sdsfree(reply);
+ c->reply_bytes = 0;
cleanup:
/* Clean up. Command code may have changed argv/argc so we use the