Skip to content

Commit cfdeb35

Browse files
committed
fix(core): Memory Leak
1 parent ef36670 commit cfdeb35

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/engine/vgui/ScreenText.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "ScreenText.h"
22

3+
extern std::map<CEntityInstance*, CEntityKeyValues*> entKeyVal;
4+
35
ScreenText::ScreenText() {}
46

57
ScreenText::~ScreenText()
@@ -22,6 +24,11 @@ void ScreenText::Create(Color color, std::string font, int size, bool drawBackgr
2224

2325
CEntityKeyValues* pMenuKV = new CEntityKeyValues();
2426

27+
if(entKeyVal.find(pScreenEntity.Get()) != entKeyVal.end())
28+
delete entKeyVal[pScreenEntity.Get()];
29+
30+
entKeyVal[pScreenEntity.Get()] = pMenuKV;
31+
2532
pMenuKV->SetBool("enabled", false);
2633
pMenuKV->SetFloat("world_units_per_pixel", (0.25 / 1050) * size);
2734
pMenuKV->SetInt("justify_horizontal", 0);
@@ -67,7 +74,7 @@ void ScreenText::SetupViewForPlayer(Player* player)
6774

6875
void ScreenText::SetText(std::string text)
6976
{
70-
m_text = text;
77+
m_text = text.c_str();
7178

7279
if (!pScreenEntity) return;
7380

src/entitysystem/entities/listener.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
PluginEvent* pEvent = nullptr;
44
CEntityListener g_entityListener;
55

6+
std::map<CEntityInstance*, CEntityKeyValues*> entKeyVal;
7+
68
void EntityListener::Initialize()
79
{
810
SH_ADD_HOOK_MEMFUNC(INetworkServerService, StartupServer, g_pNetworkServerService, this, &EntityListener::StartupServer, true);
@@ -58,4 +60,9 @@ void CEntityListener::OnEntityDeleted(CEntityInstance* pEntity)
5860
{
5961
if (!pEvent) pEvent = new PluginEvent("core", nullptr, nullptr);
6062
g_pluginManager->ExecuteEvent("core", "OnEntityDeleted", encoders::msgpack::SerializeToString({ string_format("%p", (void*)pEntity), "CEntityInstance" }), pEvent);
63+
64+
if(entKeyVal.find(pEntity) != entKeyVal.end()) {
65+
delete entKeyVal[pEntity];
66+
entKeyVal.erase(pEntity);
67+
}
6168
}

vendor/embedder

0 commit comments

Comments
 (0)