From d9ee1af1f6396ea2933d87c9b31c4445d9910134 Mon Sep 17 00:00:00 2001 From: Sarrum Date: Sun, 11 Oct 2020 03:58:16 +0300 Subject: [PATCH] Fix engineGetModelTextures memory leak (#1704) Co-authored-by: Qais Patankar --- Client/core/CCredits.cpp | 1 + Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Client/core/CCredits.cpp b/Client/core/CCredits.cpp index da3a7a2a09..7bb1348b29 100644 --- a/Client/core/CCredits.cpp +++ b/Client/core/CCredits.cpp @@ -182,6 +182,7 @@ CCredits::CCredits() "pentaflops\n" "knitz12\n" "ApeLsiN4eG\n" + "theSarrum\n" "AlιAѕѕaѕѕιN\n" "PerikiyoXD\n" "correaAlex\n" diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index b8d8c2b41d..99e80011a9 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -1126,11 +1126,18 @@ int CLuaEngineDefs::EngineGetModelTextures(lua_State* luaVM) if (argStream.HasErrors()) return luaL_error(luaVM, argStream.GetFullErrorMessage()); + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); + CResource* pParentResource = pLuaMain->GetResource(); + lua_newtable(luaVM); for (const auto& pair : textureList) { CClientTexture* pTexture = g_pClientGame->GetManager()->GetRenderElementManager()->CreateTexture("", &std::get<1>(pair), RDEFAULT, RDEFAULT, RDEFAULT, RFORMAT_UNKNOWN, TADDRESS_WRAP); + if (pTexture) + { + pTexture->SetParent(pParentResource->GetResourceDynamicEntity()); + } lua_pushstring(luaVM, std::get<0>(pair).c_str()); lua_pushelement(luaVM, pTexture); lua_settable(luaVM, -3);