From 0ef8ff7af3e260576a066f27b24dc79ea8515e72 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 22 Jan 2012 18:48:44 +0800 Subject: Fixed use of checkstring method in the script functions luaL_checkstring might not return so the destructor of string will not be called. Reviewed-by: Bjorn. --- src/scripting/lua.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index a03bc574..eb50f168 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -80,7 +80,7 @@ static int npc_message(lua_State *s) } MessageOut msg(GPMSG_NPC_MESSAGE); msg.writeInt16(p->getPublicID()); - msg.writeString(std::string(m), l); + msg.writeString(m, l); gameHandler->sendTo(q, msg); return 0; } @@ -2464,9 +2464,11 @@ static int get_distance(lua_State *s) static int map_get_objects(lua_State *s) { const bool filtered = (lua_gettop(s) == 1); - std::string filter; + const char *filter; if (filtered) + { filter = luaL_checkstring(s, 1); + } lua_pushlightuserdata(s, (void *)®istryKey); lua_gettable(s, LUA_REGISTRYINDEX); @@ -2497,7 +2499,7 @@ static int map_get_objects(lua_State *s) */ static int map_object_get_property(lua_State *s) { - std::string key = luaL_checkstring(s, 2); + const char *key = luaL_checkstring(s, 2); if (!lua_islightuserdata(s, 1)) { raiseScriptError(s, "map_object_get_property called with invalid" @@ -2602,7 +2604,8 @@ static int announce(lua_State *s) static int require_loader(lua_State *s) { // Add .lua extension (maybe only do this when it doesn't have it already) - std::string filename = luaL_checkstring(s, 1); + const char *file = luaL_checkstring(s, 1); + std::string filename = file; filename.append(".lua"); const std::string path = ResourceManager::resolve(filename); -- cgit v1.2.3-60-g2f50