diff options
author | antirez <antirez@gmail.com> | 2017-12-04 10:33:04 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2017-12-04 10:33:04 +0100 |
commit | 68681f2bcf8d17e573c27ff3fc676ddde381204c (patch) | |
tree | 917249f9683c137bab08fb6f0dfce56cc0b29fb0 | |
parent | 6f0b19bc5b0f89d7d9d89e84de1f4c9a859df59c (diff) | |
download | redis-68681f2bcf8d17e573c27ff3fc676ddde381204c.tar.gz |
Fix issue #4505, Lua RDB AUX field loading of existing scripts.
Unfortunately, as outlined by @soloestoy in #4505, "lua" AUX RDB field
loading in case of duplicated script was still broken. This commit fixes
this problem and also a memory leak introduced by the past commit.
Note that now we have a regression test able to duplicate the issue, so
this commit was actually tested against the regression. The original PR
also had a valid fix, but I prefer to hide the details of scripting.c
outside scripting.c, and later "SCRIPT LOAD" should also be able to use
the function luaCreateFunction() instead of redoing the work.
-rw-r--r-- | src/scripting.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/scripting.c b/src/scripting.c index ea167365a..9427b7b6b 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -1161,7 +1161,6 @@ int redis_math_randomseed (lua_State *L) { * On error C_ERR is returned and an appropriate error is set in the * client context. */ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body, int allow_dup) { - sds funcdef = sdsempty(); char fname[43]; if (funcname == NULL) { @@ -1171,9 +1170,16 @@ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body, int funcname = fname; } - if (allow_dup && dictFind(server.lua_scripts,funcname+2) != NULL) - return C_OK; + if (allow_dup) { + sds sha = sdsnewlen(funcname+2,40); + if (allow_dup && dictFind(server.lua_scripts,sha) != NULL) { + sdsfree(sha); + return C_OK; + } + sdsfree(sha); + } + sds funcdef = sdsempty(); funcdef = sdscat(funcdef,"function "); funcdef = sdscatlen(funcdef,funcname,42); funcdef = sdscatlen(funcdef,"() ",3); |