Bara / fuckZones

17 stars 9 forks source link

Infinite handle bug #103

Open eyal282 opened 1 year ago

eyal282 commented 1 year ago

Not 100% sure why, because no error logs. I came across this and noticed the clone is not closed. smKeys

bool AddEffectToZone(int entity, const char[] effect)
{
    if (g_kvConfig == null)
    {
        return false;
    }

    g_kvConfig.Rewind();

    char sName[MAX_ZONE_NAME_LENGTH];
    GetZoneNameByIndex(entity, sName, sizeof(sName));

    if (!g_kvConfig.JumpToKey(sName))
    {
        return false;
    }

    if (!g_kvConfig.JumpToKey("effects", true))
    {
        return false;
    }

    if (!g_kvConfig.JumpToKey(effect, true))
    {
        return false;
    }

    StringMap keys = null;
    g_smEffectKeys.GetValue(effect, keys);

    if (keys != null)
    {
        StringMap smKeys = view_as<StringMap>(CloneHandle(keys));
        Zone[entity].Effects.SetValue(effect, smKeys);

        StringMapSnapshot map = smKeys.Snapshot();

        for (int i = 0; i < map.Length; i++)
        {
            char sKey[MAX_KEY_NAME_LENGTH];
            map.GetKey(i, sKey, sizeof(sKey));

            char sValue[MAX_KEY_VALUE_LENGTH];
            smKeys.GetString(sKey, sValue, sizeof(sValue));

            g_kvConfig.SetString(sKey, sValue);
        }

        delete map;
    }

    g_kvConfig.Rewind();

    SaveMapConfig();
    CallZoneEffectUpdate(entity);

    return true;
}