From 7f7ff36ad258e4cd01dd2fe8742befe3c73f4293 Mon Sep 17 00:00:00 2001 From: Emma Miler <27428383+emma-miler@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:43:48 +0100 Subject: Fix a memory leak for `setupfunc` (#103) --- NorthstarDedicatedTest/squirrel.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h index b01618f2..7801ada7 100644 --- a/NorthstarDedicatedTest/squirrel.h +++ b/NorthstarDedicatedTest/squirrel.h @@ -205,14 +205,20 @@ template class SquirrelManager ClientSq_pushroottable(sqvm2); ClientSq_pushstring(sqvm2, funcname, -1); result = ClientSq_sq_get(sqvm2, -2); - ClientSq_pushroottable(sqvm2); + if (result != SQRESULT_ERROR) + { + ClientSq_pushroottable(sqvm2); + } } else if (context == ScriptContext::SERVER) { ServerSq_pushroottable(sqvm2); ServerSq_pushstring(sqvm2, funcname, -1); result = ServerSq_sq_get(sqvm2, -2); - ServerSq_pushroottable(sqvm2); + if (result != SQRESULT_ERROR) + { + ServerSq_pushroottable(sqvm2); + } } return result; } @@ -282,4 +288,4 @@ template class SquirrelManager extern SquirrelManager* g_ClientSquirrelManager; extern SquirrelManager* g_ServerSquirrelManager; -extern SquirrelManager* g_UISquirrelManager; \ No newline at end of file +extern SquirrelManager* g_UISquirrelManager; -- cgit v1.2.3