Skip to content

Commit 84c0dfb

Browse files
committed
Next try :/
1 parent 57ee7ed commit 84c0dfb

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

source/lua_LuaThread.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,17 @@ LUA_FUNCTION(LuaThread_SetValue)
107107
if (type == GarrysMod::Lua::Type::Nil)
108108
{
109109
shared_table_mutex.Lock();
110-
ILuaValue* pKey = nullptr;
111-
ILuaValue* pVal = nullptr;
112-
for (auto& [sKey, sVal] : shared_table)
110+
for (auto it = shared_table.begin(); it != shared_table.end();)
113111
{
114-
if (EqualValue(key, sKey))
112+
if (EqualValue(key, it->first))
115113
{
116-
pKey = sKey;
117-
pVal = sVal;
114+
SafeDelete(it->first);
115+
SafeDelete(it->second);
116+
it = shared_table.erase(it);
118117
break;
119118
}
120-
}
121119

122-
if (pKey)
123-
{
124-
shared_table.erase(pKey);
125-
//SafeDelete(pKey); // Potential memory leak? idk but it causes weird behavior.
126-
SafeDelete(pVal);
120+
++it;
127121
}
128122
shared_table_mutex.Unlock();
129123
SafeDelete(key);

0 commit comments

Comments
 (0)