From bfe8eeb4b390bf19767b880b5cba0a5475edf495 Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Mon, 14 Dec 2015 15:17:40 +0800 Subject: [PATCH] Fix dangling c pointer to lua string value Lua string object referenced by C pointer from lua_tolstring() was removed from stack by lua_settop(L,0). Lua 5.3 Reference Manual says: > Because Lua has garbage collection, there is no guarantee that the > pointer returned by lua_tolstring will be valid after the > corresponding Lua value is removed from the stack. That is it. Introduced in commit 9937081854c7b65d0a0557c3630ecbf1d62622d8. --- lualib-src/lua-seri.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lualib-src/lua-seri.c b/lualib-src/lua-seri.c index c0761bd5..d80452b6 100644 --- a/lualib-src/lua-seri.c +++ b/lualib-src/lua-seri.c @@ -572,7 +572,7 @@ _luaseri_unpack(lua_State *L) { return luaL_error(L, "deserialize null pointer"); } - lua_settop(L,0); + lua_settop(L,1); struct read_block rb; rball_init(&rb, buffer, len); @@ -591,7 +591,7 @@ _luaseri_unpack(lua_State *L) { // Need not free buffer - return lua_gettop(L); + return lua_gettop(L) - 1; } int