Raised This Month: $203 Target: $400
 50% 

Solved DataPacks and queries leaking?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xm3kilo
Member
Join Date: Jan 2018
Old 03-10-2018 , 08:27   DataPacks and queries leaking?
Reply With Quote #1

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

Last edited by xm3kilo; 03-13-2018 at 14:47.
xm3kilo is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-10-2018 , 09:18   Re: DataPacks and queries leaking?
Reply With Quote #2

IQuery handles are for database queries, not your datapacks. You'll have to post more code.
Fyren is offline
xm3kilo
Member
Join Date: Jan 2018
Old 03-10-2018 , 09:32   Re: DataPacks and queries leaking?
Reply With Quote #3

Quote:
Originally Posted by Fyren View Post
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

Last edited by xm3kilo; 03-10-2018 at 09:32.
xm3kilo is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 03-10-2018 , 10:00   Re: DataPacks and queries leaking?
Reply With Quote #4

Quote:
Originally Posted by Fyren View Post
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.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
xm3kilo
Member
Join Date: Jan 2018
Old 03-10-2018 , 10:04   Re: DataPacks and queries leaking?
Reply With Quote #5

Quote:
Originally Posted by arne1288 View Post
^ 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
xm3kilo is offline
pride95
Senior Member
Join Date: Aug 2015
Old 03-10-2018 , 11:20   Re: DataPacks and queries leaking?
Reply With Quote #6

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.
pride95 is offline
xm3kilo
Member
Join Date: Jan 2018
Old 03-10-2018 , 12:44   Re: DataPacks and queries leaking?
Reply With Quote #7

Quote:
Originally Posted by pride95 View Post
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.
xm3kilo is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-10-2018 , 14:01   Re: DataPacks and queries leaking?
Reply With Quote #8

Quote:
Originally Posted by xm3kilo View Post
The plugin is 4000 lines.
The forum can handle it.
__________________
asherkin is offline
brunoronning
Senior Member
Join Date: Jan 2014
Location: Brazil
Old 03-11-2018 , 04:17   Re: DataPacks and queries leaking?
Reply With Quote #9

Quote:
Originally Posted by xm3kilo View Post
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.
brunoronning is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-11-2018 , 06:27   Re: DataPacks and queries leaking?
Reply With Quote #10

Quote:
Originally Posted by brunoronning View Post
Try this method:
You now have a very obvious leak on any query failure.
__________________
asherkin is offline
Reply


Thread Tools
Display Modes

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 10:12.


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