Fixed memory leak in infection countdown feature.

This commit is contained in:
Richard Helgeby 2012-05-31 12:43:48 +02:00
parent 16280e0397
commit 5340e9be58

View File

@ -54,6 +54,11 @@ new Handle:tInfectCountdown = INVALID_HANDLE;
* @endsection * @endsection
*/ */
/**
* Infection countdown data pack.
*/
new Handle:hInfectCountdownData = INVALID_HANDLE;
/** /**
* Array for flagging client as zombie. * Array for flagging client as zombie.
*/ */
@ -82,6 +87,7 @@ InfectOnMapEnd()
// still running. // still running.
ZREndTimer(tInfect); ZREndTimer(tInfect);
ZREndTimer(tInfectCountdown); ZREndTimer(tInfectCountdown);
InfectStopCountdown();
} }
/** /**
@ -381,14 +387,17 @@ InfectOnRoundFreezeEnd()
new bool:countdown = GetConVarBool(g_hCvarsList[CVAR_INFECT_MZOMBIE_COUNTDOWN]); new bool:countdown = GetConVarBool(g_hCvarsList[CVAR_INFECT_MZOMBIE_COUNTDOWN]);
if (countdown && randomtime > 1.0) if (countdown && randomtime > 1.0)
{ {
// Stop old countdown timer, if it exists.
InfectStopCountdown();
// Store the time until infection, and initialize the counter. // Store the time until infection, and initialize the counter.
new Handle:hCountdownData = CreateDataPack(); hInfectCountdownData = CreateDataPack();
WritePackFloat(hCountdownData, randomtime); WritePackFloat(hInfectCountdownData, randomtime);
WritePackFloat(hCountdownData, 0.0); WritePackFloat(hInfectCountdownData, 0.0);
tInfectCountdown = CreateTimer(1.0, InfectCountdown, hCountdownData, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); tInfectCountdown = CreateTimer(1.0, InfectCountdown, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
// Display initial tick. // Display initial tick.
InfectCountdown(tInfectCountdown, hCountdownData); InfectCountdown(tInfectCountdown);
} }
} }
@ -564,28 +573,24 @@ public Action:InfectMotherZombie(Handle:timer)
* *
* @param timer The timer handle. * @param timer The timer handle.
*/ */
public Action:InfectCountdown(Handle:timer, Handle:hCountdownData) public Action:InfectCountdown(Handle:timer)
{ {
new bool:countdown = GetConVarBool(g_hCvarsList[CVAR_INFECT_MZOMBIE_COUNTDOWN]); new bool:countdown = GetConVarBool(g_hCvarsList[CVAR_INFECT_MZOMBIE_COUNTDOWN]);
if (!countdown) if (!countdown)
{ {
// Kill the timer. InfectStopCountdown();
ZREndTimer(tInfectCountdown, false);
CloseHandle(hCountdownData);
return Plugin_Stop; return Plugin_Stop;
} }
// Read the info from the datapack. // Read the info from the datapack.
ResetPack(hCountdownData); ResetPack(hInfectCountdownData);
new Float:length = ReadPackFloat(hCountdownData); new Float:length = ReadPackFloat(hInfectCountdownData);
new Float:counter = ReadPackFloat(hCountdownData); new Float:counter = ReadPackFloat(hInfectCountdownData);
// Check if the countdown has finished. // Check if the countdown has finished.
if (counter >= length) if (counter >= length)
{ {
// Kill timer. InfectStopCountdown();
ZREndTimer(tInfectCountdown);
CloseHandle(hCountdownData);
return Plugin_Stop; return Plugin_Stop;
} }
@ -595,13 +600,29 @@ public Action:InfectCountdown(Handle:timer, Handle:hCountdownData)
counter++; counter++;
// Write the new counter value to the datapack. // Write the new counter value to the datapack.
ResetPack(hCountdownData); ResetPack(hInfectCountdownData);
WritePackFloat(hCountdownData, length); WritePackFloat(hInfectCountdownData, length);
WritePackFloat(hCountdownData, counter); WritePackFloat(hInfectCountdownData, counter);
return Plugin_Continue; return Plugin_Continue;
} }
/**
* Stops the infection countdown timer.
*/
InfectStopCountdown()
{
// Kill the timer.
ZREndTimer(tInfectCountdown);
// Destroy data pack.
if (hInfectCountdownData != INVALID_HANDLE)
{
CloseHandle(hInfectCountdownData);
hInfectCountdownData = INVALID_HANDLE;
}
}
/** /**
* Infects a client. Execute events, sets attributes and flags that indicate * Infects a client. Execute events, sets attributes and flags that indicate
* that the client is a zombie. * that the client is a zombie.