Raised This Month: $51 Target: $400
 12% 

[Help] MEMORY LEAK DETECTED IN PLUGIN


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shit on shoe
Senior Member
Join Date: Jul 2010
Old 11-24-2011 , 06:46   [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #1

this plugin have problem since valve update:

sourcemod_fatal.log show me this:
Code:
22:23:02: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "teambalancer.smx")
L 11/21/2011 - 22:23:02: [SM] Unloading plugin to free 8992 handles.
L 11/21/2011 - 22:23:02: [SM] Contact the author(s) of this plugin to correct this error.
anyone can tell me how i can fix this ?
the scripter of this script is not activ...

here is the .sp
Code:
// 1 spec
// 2 Ts
// 3 Cts

#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define FADE_IN 0x0001
#define SPEC 1
#define TS 2
#define CTS 3 

new Handle:g_Cvar_round_restart_delay;
new Handle:g_adtClientlist;
new Handle:g_adtPlayers;
new g_teamT;
new g_teamCT;
new g_diff;

public Plugin:myinfo =
{
    name = "Team-Balancer",
    author = "FreeZ",
    version = "1.1",
    description = "Simple Team-Balancer",
    url = "http://gts-fun.de"
};

public OnPluginStart()
{
    HookEvent("round_end", Event_RoundEnd)
    g_Cvar_round_restart_delay = FindConVar("mp_round_restart_delay");
    PrintToChatAll("[TB] Team-Balancer is loaded")
}

public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    new Float:restart_delay = GetConVarFloat(g_Cvar_round_restart_delay);
        
    CreateTimer((restart_delay-0.1), Balance);
}

public Action:Balance(Handle:timer)
{
    g_teamT = GetTeamClientCount(TS);
    g_teamCT = GetTeamClientCount(CTS);
    g_diff = g_teamT - g_teamCT;
    
    if (g_diff < 0)
    {
        g_diff = -g_diff;
    }
    
    g_diff = RoundToFloor(Float:(g_diff/2.0)+1);
    
    g_adtClientlist = CreateArray(3);
    g_adtPlayers = CreateArray(3);
    
    if (g_teamT > (g_teamCT + 1))
    {
        if (GetTeamClientCount(TS) > 0)
        {
            //Clientliste erstellen
            for (new i = 1; i <= MaxClients; i++)
            {
                if (IsClientInGame(i) && IsClientConnected(i) && (GetClientTeam(i) == TS) && (GetUserAdmin(i) == INVALID_ADMIN_ID))
                {
                    PushArrayCell(g_adtClientlist, i);
                }
            }
            clientuebergeber();
        }
        switcher(0, 0, 255, 255, FADE_IN, CTS);
    }
    
    if (g_teamCT > (g_teamT + 1))
    {
        if (GetTeamClientCount(CTS) > 0)
        {
            //Clientliste erstellen
            for (new i = 1; i <= MaxClients; i++)
            {
                if (IsClientInGame(i) && IsClientConnected(i) && (GetClientTeam(i) == CTS) && (GetUserAdmin(i) == INVALID_ADMIN_ID))
                {
                    PushArrayCell(g_adtClientlist, i);
                }
            }
            clientuebergeber();
        }
        switcher(255, 0, 0, 255, FADE_IN, TS);
    }

}

public Action:clientuebergeber()
{
    new randomnumber;
    
    if (GetArraySize(g_adtClientlist)+1 < g_diff)
    {
        g_diff = GetArraySize(g_adtClientlist)+1;
    }

    //Switch-Clientliste erstellen
    for (new j=1; j<g_diff; j++)
    {
        randomnumber = GetRandomInt(0, GetArraySize(g_adtClientlist)-1);
        PushArrayCell(g_adtPlayers, GetArrayCell(g_adtClientlist, randomnumber));
        RemoveFromArray(g_adtClientlist, randomnumber);
    }

}

public Action:switcher(red, green, blue, alpha, type, newteam)
{
    new Handle:msg;
    new duration;
    
    duration = 0;
        
    for (new i=1; i<g_diff; i++)
    {
        CS_SwitchTeam(GetArrayCell(g_adtPlayers, i-1), newteam);
        PrintCenterText(GetArrayCell(g_adtPlayers, i-1), "ACHTUNG: Du bist nun im anderen Team!")
        
        msg = StartMessageOne("Fade", GetArrayCell(g_adtPlayers, i-1));
        BfWriteShort(msg, 500);
        BfWriteShort(msg, duration);
        BfWriteShort(msg, type);
        BfWriteByte(msg, red);
        BfWriteByte(msg, green);
        BfWriteByte(msg, blue);
        BfWriteByte(msg, alpha);
        EndMessage();
    }
    
    ClearArray(g_adtClientlist);
    ClearArray(g_adtPlayers);
    
}
__________________

Last edited by Shit on shoe; 11-24-2011 at 06:47.
Shit on shoe is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-24-2011 , 07:11   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #2

That problem come from "Array", every round... what I quick looked.
Code:
0x010700b7    test\teambala.smx       CellArray               16        
0x00eb00b8    test\teambala.smx       CellArray               16        
0x014700b9    test\teambala.smx       CellArray               16        
0x00ec00ba    test\teambala.smx       CellArray               16        
0x010800bb    test\teambala.smx       CellArray               16        
0x017300bc    test\teambala.smx       CellArray               16        
0x014800bd    test\teambala.smx       CellArray               16        
0x019f00be    test\teambala.smx       CellArray               16        
0x017400bf    test\teambala.smx       CellArray               16        
0x01b700c0    test\teambala.smx       CellArray               16        
0x01a000c1    test\teambala.smx       CellArray               16        
0x01f700c2    test\teambala.smx       CellArray               16        
0x01b800c3    test\teambala.smx       CellArray               16        
0x023d00c4    test\teambala.smx       CellArray               16        
0x01f800c5    test\teambala.smx       CellArray               16        
0x021100c6    test\teambala.smx       CellArray               16        
0x021200c7    test\teambala.smx       CellArray               16        
0x023e00c9    test\teambala.smx       CellArray               16
*I have renamed plugin name
__________________
Do not Private Message @me
Bacardi is offline
Shit on shoe
Senior Member
Join Date: Jul 2010
Old 11-24-2011 , 12:44   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
That problem come from "Array", every round... what I quick looked.
Code:
0x010700b7    test\teambala.smx       CellArray               16        
0x00eb00b8    test\teambala.smx       CellArray               16        
0x014700b9    test\teambala.smx       CellArray               16        
0x00ec00ba    test\teambala.smx       CellArray               16        
0x010800bb    test\teambala.smx       CellArray               16        
0x017300bc    test\teambala.smx       CellArray               16        
0x014800bd    test\teambala.smx       CellArray               16        
0x019f00be    test\teambala.smx       CellArray               16        
0x017400bf    test\teambala.smx       CellArray               16        
0x01b700c0    test\teambala.smx       CellArray               16        
0x01a000c1    test\teambala.smx       CellArray               16        
0x01f700c2    test\teambala.smx       CellArray               16        
0x01b800c3    test\teambala.smx       CellArray               16        
0x023d00c4    test\teambala.smx       CellArray               16        
0x01f800c5    test\teambala.smx       CellArray               16        
0x021100c6    test\teambala.smx       CellArray               16        
0x021200c7    test\teambala.smx       CellArray               16        
0x023e00c9    test\teambala.smx       CellArray               16
*I have renamed plugin name
ok but how to fix ?
__________________
Shit on shoe is offline
Kevin_b_er
SourceMod Donor
Join Date: Feb 2009
Old 11-24-2011 , 23:14   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #4

You need to use CloseHandle instead of ClearArray. All ClearArray does is set the array to 0 size, but the array object remains.

(The array object itself takes up memory too. Even if there's no script-usable data in the array)

Don't just change the ClearArray's to CloseHandle's, either. Make sure that every CreateArray is paired with a CloseHandle. the switch function does not look like it always runs.
__________________
Kevin_b_er is offline
Shit on shoe
Senior Member
Join Date: Jul 2010
Old 11-25-2011 , 13:16   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #5

ok thx for your information kevin, but im not a coder maybe you can make me example how to change it ?
__________________
Shit on shoe is offline
Kevin_b_er
SourceMod Donor
Join Date: Feb 2009
Old 11-25-2011 , 21:50   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #6

You must use CloseHandle on the array after you create it with CreateArray, or the array leaks memory.

Take out the two ClearArray lines in switcher and put two similar CloseHandle calls at the end switcher.
__________________
Kevin_b_er is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-26-2011 , 07:29   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #7

Quote:
Originally Posted by Shit on shoe View Post
but im not a coder maybe you can make me example how to change it ?
The Scripting section is for plugin developers, thread moved to Requests.
__________________
asherkin is offline
Shit on shoe
Senior Member
Join Date: Jul 2010
Old 11-26-2011 , 12:00   Re: [Help] MEMORY LEAK DETECTED IN PLUGIN
Reply With Quote #8

Quote:
Originally Posted by Kevin_b_er View Post
You must use CloseHandle on the array after you create it with CreateArray, or the array leaks memory.

Take out the two ClearArray lines in switcher and put two similar CloseHandle calls at the end switcher.
ClearArray(g_adtClientlist);
ClearArray(g_adtPlayers);

So this lines should be delete and put two closehandle, right ?
__________________
Shit on shoe is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode