Commit 68681f2b authored by antirez's avatar antirez
Browse files

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.
parent 6f0b19bc
...@@ -1161,7 +1161,6 @@ int redis_math_randomseed (lua_State *L) { ...@@ -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 * On error C_ERR is returned and an appropriate error is set in the
* client context. */ * client context. */
int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body, int allow_dup) { int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body, int allow_dup) {
sds funcdef = sdsempty();
char fname[43]; char fname[43];
if (funcname == NULL) { if (funcname == NULL) {
...@@ -1171,9 +1170,16 @@ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body, int ...@@ -1171,9 +1170,16 @@ int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body, int
funcname = fname; funcname = fname;
} }
if (allow_dup && dictFind(server.lua_scripts,funcname+2) != NULL) if (allow_dup) {
sds sha = sdsnewlen(funcname+2,40);
if (allow_dup && dictFind(server.lua_scripts,sha) != NULL) {
sdsfree(sha);
return C_OK; return C_OK;
}
sdsfree(sha);
}
sds funcdef = sdsempty();
funcdef = sdscat(funcdef,"function "); funcdef = sdscat(funcdef,"function ");
funcdef = sdscatlen(funcdef,funcname,42); funcdef = sdscatlen(funcdef,funcname,42);
funcdef = sdscatlen(funcdef,"() ",3); funcdef = sdscatlen(funcdef,"() ",3);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment