From 723038052e38830131a17425e1603d951ec08603 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2009 18:11:31 +0200 Subject: [PATCH] Fixed potential memory leak in class system. --- src/zr/playerclasses/classmenus.inc | 3 +++ src/zr/playerclasses/filtertools.inc | 9 ++++++++- src/zr/playerclasses/playerclasses.inc | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/zr/playerclasses/classmenus.inc b/src/zr/playerclasses/classmenus.inc index f9ed80d..18130ff 100644 --- a/src/zr/playerclasses/classmenus.inc +++ b/src/zr/playerclasses/classmenus.inc @@ -231,6 +231,9 @@ ClassMenuSelect(client, teamid) } } + // Destroy array. + CloseHandle(classarray); + SetMenuExitBackButton(menu, true); DisplayMenu(menu, client, MENU_TIME_FOREVER); } diff --git a/src/zr/playerclasses/filtertools.inc b/src/zr/playerclasses/filtertools.inc index 51a4d0c..aa86c85 100644 --- a/src/zr/playerclasses/filtertools.inc +++ b/src/zr/playerclasses/filtertools.inc @@ -693,6 +693,7 @@ stock ClassGetRandomClass(teamfilter = -1, bool:ignoreEnabled = false, requirefl new Handle:classarray; new arraycount; new randnum; + new buffer; classarray = CreateArray(); @@ -704,11 +705,14 @@ stock ClassGetRandomClass(teamfilter = -1, bool:ignoreEnabled = false, requirefl randnum = GetRandomInt(0, arraycount - 1); // Return the value at the random index. - return GetArrayCell(classarray, randnum); + buffer = GetArrayCell(classarray, randnum); + CloseHandle(classarray); + return buffer; } else { // Failed to get a random class. + CloseHandle(classarray); return -1; } } @@ -808,6 +812,7 @@ stock ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, requireflags = 0, if (!ClassAddToArray(classarray, teamid, ignoreEnabled, requireflags, denyflags, cachetype)) { // Failed to get classes. + CloseHandle(classarray); return -1; } @@ -822,10 +827,12 @@ stock ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, requireflags = 0, if (ClassGetTeamDefault(classindex, cachetype)) { // Default class found. + CloseHandle(classarray); return classindex; } } + CloseHandle(classarray); return -1; } diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index e06a73c..c8734b1 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -544,6 +544,9 @@ ClassLoad(bool:keepMultipliers = false) ConfigSetConfigReloadFunc(File_Classes, GetFunctionByName(GetMyHandle(), "ClassOnConfigReload")); // ConfigSetConfigHandle(File_Classes, INVALID_HANDLE); ConfigSetConfigPath(File_Classes, pathclasses); + + // Remove key/value cache. + CloseHandle(kvClassData); } /**