Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Keyvalues/DataPacks memory leaks #212

Closed
naydef opened this issue Jul 2, 2024 · 2 comments
Closed

[Bug] Keyvalues/DataPacks memory leaks #212

naydef opened this issue Jul 2, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@naydef
Copy link
Contributor

naydef commented Jul 2, 2024

Fix diff:

------------ addons/sourcemod/scripting/freak_fortress_2/weapons.sp ------------
index 6ef13a2b..1c9529bd 100755
@@ -306,6 +306,7 @@ void Weapons_ShowChanges(int client, int entity)
 		{
 			CPrintToChat(client, "%t%s:", "Prefix", localizedWeaponName);
 		}
+		delete kv;
 	}
 	else
 	#endif
@@ -649,6 +650,7 @@ stock void Weapons_OnHitBoss(int attacker, int newPlayerDamage, int lastPlayerDa
 					if(value)
 						SetEntProp(attacker, Prop_Data, "m_iAmmo", GetEntProp(attacker, Prop_Data, "m_iAmmo", _, 2) + value, _, 2);
 				}
+				delete kv;
 			}
 		}
 	}
@naydef naydef added the bug Something isn't working label Jul 2, 2024
@naydef
Copy link
Contributor Author

naydef commented Jul 2, 2024

Well, it turns out FF2R is also leaking DataPack handles.
It seems it's due to assuming that CreateDataTimer is not creating the DataPack itself.

Fix diff (ignore whitespace changes):

---------- addons/sourcemod/scripting/freak_fortress_2/attributes.sp ----------
index edc65800..8fa2cfd2 100755
@@ -88,7 +88,7 @@ bool Attributes_OnBackstabBoss(int attacker, int victim, float &damage, int weap
 	/*
 	if(Attributes_FindOnWeapon(attacker, weapon, 217))	// sanguisuge
 	{
-		
+
 		int maxoverheal = TF2U_GetMaxOverheal(attacker) * 2;	// 250% overheal (from 200% overheal)
 		int health = GetClientHealth(attacker);
 		if(health < maxoverheal)
@@ -105,7 +105,7 @@ bool Attributes_OnBackstabBoss(int attacker, int victim, float &damage, int weap
 			if(TF2_IsPlayerInCondition(attacker, TFCond_Plague))
 				TF2_RemoveCondition(attacker, TFCond_Plague);
 		}
-		
+
 	}
 	*/
 
@@ -311,7 +311,7 @@ void Attributes_OnHitBoss(int attacker, int victim, int inflictor, float fdamage
 
 	if(Attributes_FindOnPlayer(attacker, 418) > 0.0)	// boost on damage
 	{
-		DataPack pack = new DataPack();
+		DataPack pack;
 		if(Enabled)
 		{
 			CreateDataTimer(0.1, Attributes_BoostDrainStack, pack, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);

----------- addons/sourcemod/scripting/freak_fortress_2/commands.sp -----------
index 614dc0eb..4f7a3df2 100755
@@ -275,7 +275,7 @@ static Action SwapTeam(int client, int wantTeam)
 
 		if(Cvar[AggressiveSwap].BoolValue)
 		{
-			DataPack pack = new DataPack();
+			DataPack pack;
 			CreateDataTimer(0.2, Command_AggressiveSwap, pack, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
 			pack.WriteCell(GetClientUserId(client));
 			pack.WriteCell(newTeam);

@naydef naydef changed the title [Bug] Keyvalues memory leak when using weapons with custom attributes [Bug] Keyvalues/DataPack memory leaks Jul 2, 2024
@naydef naydef changed the title [Bug] Keyvalues/DataPack memory leaks [Bug] Keyvalues/DataPacks memory leaks Jul 2, 2024
@naydef
Copy link
Contributor Author

naydef commented Aug 13, 2024

The second type of memory leaks (DataPack one) hasn't been taken care of.

@Batfoxkid Batfoxkid reopened this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants