AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved DataPacks and queries leaking? (https://forums.alliedmods.net/showthread.php?t=305938)

xm3kilo 03-10-2018 08:27

DataPacks and queries leaking?
 
Hey guys,

I'm having some strange issues with memory leaking.

I'm passing a datapack through a threaded SQL callback like this:

PHP Code:

DataPack pack = new DataPack();
    
pack.WriteCell(client);
    
pack.WriteString(Text); 

Then in the callback I'm closing the handle like this:

PHP Code:

DataPack pack data;
                
pack.Reset();
                
int client pack.ReadCell();
                
char Text[64];
                
pack.ReadString(Text64);
                
CloseHandle(pack); 

I do that about 50 times over the course of this plugin and I have the DataPack handle leaking which forces the plugin to crash, and I also have the:

IQuery | Count 14892

Leaking, with functions args like this:

PHP Code:

public void test(Handle:ownerHandle:HQuery, const String:error[], any data

Any ideas?

Thanks everyone

Fyren 03-10-2018 09:18

Re: DataPacks and queries leaking?
 
IQuery handles are for database queries, not your datapacks. You'll have to post more code.

xm3kilo 03-10-2018 09:32

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by Fyren (Post 2582262)
IQuery handles are for database queries, not your datapacks. You'll have to post more code.

Yeah I'm getting leaks for both.

PHP Code:

char query[255];
    
Format(querysizeof(query), "query");
    
    
tDatabase.Query(FixClientquery); 

That is one of my queries for example

DarkDeviL 03-10-2018 10:00

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by Fyren (Post 2582262)
You'll have to post more code.

^ Is still valid....

Post the full code regarding the queries and packs, if you expect any help, we are not mind readers.

xm3kilo 03-10-2018 10:04

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by arne1288 (Post 2582271)
^ Is still valid....

Post the full code regarding the queries and packs, if you expect any help, we are not mind readers.

The plugin is 4000 lines.

PHP Code:

public Action:Test(client, const String:command[], args)
{    
    new 
String:query[2000];
    
GetClientAuthString(clientauthsizeof(auth));
    
Format(querysizeof(query), "SELECT * FROM TEST");
    
    
DataPack pack = new DataPack();
    
pack.WriteCell(client);
    
pack.WriteString(Text);
    
    
tDatabase.Query(TestCheckquerypack);

    return 
Plugin_Continue;
}

public 
TestCheck(Handle:ownerHandle:HQuery, const String:error[], any data)
{
        
DataPack pack data;
        
pack.Reset();
        
int client pack.ReadCell();
        
char Text[64];
        
pack.ReadString(Text64);
                
        
CloseHandle(pack);


Here's an example of both used.. Forget the syntax errors, that's the logic I'm using

pride95 03-10-2018 11:20

Re: DataPacks and queries leaking?
 
PHP Code:


    DataPack pk 
= new DataPack();
    
    if(
iClientpk.WriteCell(GetClientSerial(iClient));
    else 
pk.WriteCell(0);

    
char cQuery[256];
    
FormatEx(cQuerysizeof(cQuery), "SELECT NULL FROM `bans_table` WHERE `steamid` = '%s';"cSteam);
    
dDatabase.Query(SQL_OnAddbanCommandcQuerypkDBPrio_Normal);


public 
void SQL_OnAddbanCommand(Database dbDBResultSet rs, const char[] errorany data)
{
    if(
rs != null)
    {
        
DataPack pk view_as<DataPack>(data);
        
pk.Reset();
        
        
int iClient GetClientFromSerial(pk.ReadCell());
        
        
etc

        delete pk
;
    }


this is what i'm using. no leak memory.

xm3kilo 03-10-2018 12:44

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by pride95 (Post 2582279)
PHP Code:


    DataPack pk 
= new DataPack();
    
    if(
iClientpk.WriteCell(GetClientSerial(iClient));
    else 
pk.WriteCell(0);

    
char cQuery[256];
    
FormatEx(cQuerysizeof(cQuery), "SELECT NULL FROM `bans_table` WHERE `steamid` = '%s';"cSteam);
    
dDatabase.Query(SQL_OnAddbanCommandcQuerypkDBPrio_Normal);


public 
void SQL_OnAddbanCommand(Database dbDBResultSet rs, const char[] errorany data)
{
    if(
rs != null)
    {
        
DataPack pk view_as<DataPack>(data);
        
pk.Reset();
        
        
int iClient GetClientFromSerial(pk.ReadCell());
        
        
etc

        delete pk
;
    }


this is what i'm using. no leak memory.

Damn, this was the output of the sourcemod_fatal.log

Code:

L 03/09/2018 - 20:43:31: --------------------------------------------------------------------------
L 03/09/2018 - 20:43:31: Type        IBaseMenu          |        Count        127
L 03/09/2018 - 20:43:31: Type        IQuery              |        Count        14892
L 03/09/2018 - 20:43:31: Type        IDatabase          |        Count        18
L 03/09/2018 - 20:43:31: Type        DataPack            |        Count        1203
L 03/09/2018 - 20:43:31: -- Approximately 165916 bytes of memory are in use by (16240) Handles.


asherkin 03-10-2018 14:01

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by xm3kilo (Post 2582272)
The plugin is 4000 lines.

The forum can handle it.

brunoronning 03-11-2018 04:17

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by xm3kilo (Post 2582297)
Damn, this was the output of the sourcemod_fatal.log

Code:

L 03/09/2018 - 20:43:31: --------------------------------------------------------------------------
L 03/09/2018 - 20:43:31: Type        IBaseMenu          |        Count        127
L 03/09/2018 - 20:43:31: Type        IQuery              |        Count        14892
L 03/09/2018 - 20:43:31: Type        IDatabase          |        Count        18
L 03/09/2018 - 20:43:31: Type        DataPack            |        Count        1203
L 03/09/2018 - 20:43:31: -- Approximately 165916 bytes of memory are in use by (16240) Handles.


Try this method:
PHP Code:

void SomeFunction()
{
    
DataPack pack = new DataPack();
    
pack.WriteCell(32);
    
pack.WriteCell(52);

    
char szQuery[128];
    
Format(szQuerysizeof(szQuery), "SELECT * FROM test");
    
g_dbTest.Query(SQLCallback_TestszQuerypack);
}

public 
void SQLCallback_Test(Database dbDBResultSet results, const char[] sErrorany data)
{
    if (
db == null || strlen(sError) > 0)
    {
        
LogError("(SQLCallback_Test) Fail at Query: %s"sError);
        return;
    }

    
int iValue1;
    
int iValue2;

    
ResetPack(data);
    
iValue1 ReadPackCell(data);
    
iValue2 ReadPackCell(data);
    
delete view_as<DataPack>(data);

    
// Your Code.


It is not elegant, but it works.

asherkin 03-11-2018 06:27

Re: DataPacks and queries leaking?
 
Quote:

Originally Posted by brunoronning (Post 2582416)
Try this method:

You now have a very obvious leak on any query failure.


All times are GMT -4. The time now is 03:01.

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