Fixed potential memory leak in class system.

This commit is contained in:
richard 2009-06-22 18:11:31 +02:00
parent 1cc0fc4dda
commit 723038052e
3 changed files with 14 additions and 1 deletions

View File

@ -231,6 +231,9 @@ ClassMenuSelect(client, teamid)
} }
} }
// Destroy array.
CloseHandle(classarray);
SetMenuExitBackButton(menu, true); SetMenuExitBackButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER); DisplayMenu(menu, client, MENU_TIME_FOREVER);
} }

View File

@ -693,6 +693,7 @@ stock ClassGetRandomClass(teamfilter = -1, bool:ignoreEnabled = false, requirefl
new Handle:classarray; new Handle:classarray;
new arraycount; new arraycount;
new randnum; new randnum;
new buffer;
classarray = CreateArray(); classarray = CreateArray();
@ -704,11 +705,14 @@ stock ClassGetRandomClass(teamfilter = -1, bool:ignoreEnabled = false, requirefl
randnum = GetRandomInt(0, arraycount - 1); randnum = GetRandomInt(0, arraycount - 1);
// Return the value at the random index. // Return the value at the random index.
return GetArrayCell(classarray, randnum); buffer = GetArrayCell(classarray, randnum);
CloseHandle(classarray);
return buffer;
} }
else else
{ {
// Failed to get a random class. // Failed to get a random class.
CloseHandle(classarray);
return -1; return -1;
} }
} }
@ -808,6 +812,7 @@ stock ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, requireflags = 0,
if (!ClassAddToArray(classarray, teamid, ignoreEnabled, requireflags, denyflags, cachetype)) if (!ClassAddToArray(classarray, teamid, ignoreEnabled, requireflags, denyflags, cachetype))
{ {
// Failed to get classes. // Failed to get classes.
CloseHandle(classarray);
return -1; return -1;
} }
@ -822,10 +827,12 @@ stock ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, requireflags = 0,
if (ClassGetTeamDefault(classindex, cachetype)) if (ClassGetTeamDefault(classindex, cachetype))
{ {
// Default class found. // Default class found.
CloseHandle(classarray);
return classindex; return classindex;
} }
} }
CloseHandle(classarray);
return -1; return -1;
} }

View File

@ -544,6 +544,9 @@ ClassLoad(bool:keepMultipliers = false)
ConfigSetConfigReloadFunc(File_Classes, GetFunctionByName(GetMyHandle(), "ClassOnConfigReload")); ConfigSetConfigReloadFunc(File_Classes, GetFunctionByName(GetMyHandle(), "ClassOnConfigReload"));
// ConfigSetConfigHandle(File_Classes, INVALID_HANDLE); // ConfigSetConfigHandle(File_Classes, INVALID_HANDLE);
ConfigSetConfigPath(File_Classes, pathclasses); ConfigSetConfigPath(File_Classes, pathclasses);
// Remove key/value cache.
CloseHandle(kvClassData);
} }
/** /**