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

Solved Solve datapack memory leak


Post New Thread Reply   
 
Thread Tools Display Modes
Visual77
Veteran Member
Join Date: Jan 2009
Old 03-06-2018 , 11:24   Re: Solve datapack memory leak
Reply With Quote #11

Quote:
Originally Posted by Mitchell View Post
At the very least I would make an ArrayList for each client, and when ever a DataPack is created you add it to the list for the given client. Then you check the list within OnClientDisconnect to see if there are any valid DataPack handles still alive, close them and log them if they are. This would be easier then creating a Timer for each DataPack also. Also don't forget to search for the DataPack in the client's ArrayList first and delete it from the list before you delete the handle.

You'll need to use IsValidHandle(), as deleting (or closing) a handle wont change it's value to null else where.
https://sm.alliedmods.net/new-api/handles/IsValidHandle



Didn't see the full post of it checking the failed return value.
IsValidHandle() works, I didn't know such a thing existed (although API says it's shouldn't be used). I've been trying to understand how to validate datapacks all day, and it was already in the API.

I ran some tests and when everything works like normal, the datapack is created and in 0.1-0.3 seconds (using GetEngineTime) the datapack has been destroyed inside the query function. So a 0.4 sec timer using IsValidHandle would probably work.

However, I like your idea about the client array list better, so I'll try that. Will report back later if it fixed it.

Last edited by Visual77; 03-06-2018 at 11:26.
Visual77 is offline
pride95
Senior Member
Join Date: Aug 2015
Old 03-06-2018 , 11:51   Re: Solve datapack memory leak
Reply With Quote #12

Quote:
Originally Posted by Mitchell View Post
Didn't see the full post of it checking the failed return value.
my bad

PHP Code:

public void ClientQueryCallback_MatHack(QueryCookie cookieint clientConVarQueryResult result, const char[] cvarName, const char[] cvarValueany data)
{
    
DataPack pk view_as<DataPack>(data);

    
char cAction[32], cValue[PLATFORM_MAX_PATH];

    
pk .Reset();
    
pk .ReadString(cActionsizeof(cAction));
    
pk .ReadString(cValuesizeof(cValue));
    
int serial pk .ReadCell();
    
delete pk;

pride95 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-06-2018 , 12:13   Re: Solve datapack memory leak
Reply With Quote #13

Quote:
Originally Posted by pride95 View Post
my bad

PHP Code:

public void ClientQueryCallback_MatHack(QueryCookie cookieint clientConVarQueryResult result, const char[] cvarName, const char[] cvarValueany data)
{
    
DataPack pk view_as<DataPack>(data);

    
char cAction[32], cValue[PLATFORM_MAX_PATH];

    
pk .Reset();
    
pk .ReadString(cActionsizeof(cAction));
    
pk .ReadString(cValuesizeof(cValue));
    
int serial pk .ReadCell();
    
delete pk;

That wasn't your fault I was just on mobile and didn't see the full reply.

I also didn't know IsValidHandle was deprecated, the api page is missing all of the description etc also. seems it's deprecated however it's only supposed to be used in rare cases, which this might be one of those cases.

This also could be an issue with the query callback, what if you send a handle in and a player disconnects before firing, does the callback continue to fire? (which could be the cause of the leak).

Last edited by Mitchell; 03-06-2018 at 12:17.
Mitchell is offline
pride95
Senior Member
Join Date: Aug 2015
Old 03-06-2018 , 12:34   Re: Solve datapack memory leak
Reply With Quote #14

also, you dont need datapack in your query.
just check if the client is in game (client serial is useless for this)

send just and int (x)

PHP Code:

QueryClientConVar
(clientcheatProtectedClientCvars[x][0], ClientQueryCallback_MatHackx);

public 
void ClientQueryCallback_MatHack(QueryCookie cookieint clientConVarQueryResult result, const char[] cvarName, const char[] cvarValueany x)
{
    if (!
IsClientInGame(client
    || 
IsFakeClient(client)
    || 
result != ConVarQuery_Okay)
    {
        return;
    }    
    
    if (
StrEqual(cheatProtectedClientCvars[x][1], ACTION_EQUAL) && StringToFloat(cvarValue) != StringToFloat(cheatProtectedClientCvars[x][2]))
    {
        
HandleCheater(clientcvarNamecvarValuecheatProtectedClientCvars[x][2], cheatProtectedClientCvars[x][1]);
    }
    
    
ETC ...


Last edited by pride95; 03-06-2018 at 12:35.
pride95 is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 03-06-2018 , 12:58   Re: Solve datapack memory leak
Reply With Quote #15

Quote:
Originally Posted by pride95 View Post
also, you dont need datapack in your query.
just check if the client is in game (client serial is useless for this)

send just and int (x)

PHP Code:

QueryClientConVar
(clientcheatProtectedClientCvars[x][0], ClientQueryCallback_MatHackx);

public 
void ClientQueryCallback_MatHack(QueryCookie cookieint clientConVarQueryResult result, const char[] cvarName, const char[] cvarValueany x)
{
    if (!
IsClientInGame(client
    || 
IsFakeClient(client)
    || 
result != ConVarQuery_Okay)
    {
        return;
    }    
    
    if (
StrEqual(cheatProtectedClientCvars[x][1], ACTION_EQUAL) && StringToFloat(cvarValue) != StringToFloat(cheatProtectedClientCvars[x][2]))
    {
        
HandleCheater(clientcvarNamecvarValuecheatProtectedClientCvars[x][2], cheatProtectedClientCvars[x][1]);
    }
    
    
ETC ...

Wow, you're absolutely right Big thanks for this. I'd rather use this than dealing with pesky datapacks (datapacks = gray area)

Last edited by Visual77; 03-06-2018 at 13:02.
Visual77 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-06-2018 , 14:15   Re: Solve datapack memory leak
Reply With Quote #16

Quote:
Originally Posted by Mitchell View Post
I also didn't know IsValidHandle was deprecated, the api page is missing all of the description etc also. seems it's deprecated however it's only supposed to be used in rare cases, which this might be one of those cases.
No. He is always creating and closing the handles himself. He doesn't need IsValidHandle to figure out which are valid.
Fyren is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-06-2018 , 14:22   Re: Solve datapack memory leak
Reply With Quote #17

Quote:
Originally Posted by Fyren View Post
No. He is always creating and closing the handles himself. He doesn't need IsValidHandle to figure out which are valid.
I said might, since there seems to be a lack of information of the query callback and if the callback can be skipped if something happens within the query. From what you're saying is that CloseHandle(variable) in a one function and calling CloseHandle(variable) in a separate function wont cause any errors if the variable is the same Handle? I also don't think you were following the full conversation and I was stating that IsValidHandle would be used when storing the handle in an ArrayList to check at an later time.
Mitchell is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-06-2018 , 14:49   Re: Solve datapack memory leak
Reply With Quote #18

Quote:
Originally Posted by Mitchell View Post
From what you're saying is that CloseHandle(variable) in a one function and calling CloseHandle(variable) in a separate function wont cause any errors if the variable is the same Handle?
I said he is able to track the validity himself. I have no idea where you got that. I did not say he was tracking the validity (and he wasn't with his timer attempt).
Fyren 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 02:36.


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