Batfoxkid / Freak-Fortress-2-Rewrite

The gamemode that's now also a standalone boss maker.
https://forums.alliedmods.net/forumdisplay.php?f=154
GNU General Public License v3.0
17 stars 7 forks source link

[Bug] Keyvalues/DataPacks memory leaks #212

Open naydef opened 1 month ago

naydef commented 1 month ago

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 commented 1 month ago

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 commented 1 week ago

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