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

Memory leaks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jakesmokie
Member
Join Date: Aug 2016
Old 08-25-2016 , 00:02   Memory leaks
Reply With Quote #1

I don't know why, but my server crashes 1-3 times at day. Can this code produce some memory leaks?
And which handles do i need to delete too?
My typical menu:
PHP Code:
public void CallSomeMenu(int iClient)
{
    
Menu m CreateMenu(MenuHandler);
    
    
// Some stuff right here...
    
    
m.Display(iClient999);
}

public 
int CallSomeMenu(Menu mMenuAction mActionint iClientint iPos)
{
    if (
mAction == MenuAction_End)
        
delete m;
        
    if (
mAction != MenuAction_Select)
        return 
0;
        
    
// Another stuff..
        
    
return 0;

Query:
PHP Code:
public void OnClientPutInServer(int iClient)
{
    
char sSteam[32];
    
GetClientAuthId(iClientAuthId_Steam2sSteam31);
    
    
char sQuery[256];
    
FormatEx(sQuery255"SELECT `data` FROM `table` WHERE `steam` = '%s' LIMIT 1;"sSteam);
    
    
DB.Query(OnQueryDonesQueryiClientDBPrio_High);
}

public 
void OnQueryDone(Database hDatabaseDBResultSet hResult, const char[] sErrorint iClient)
{
    if (
hResult == null)
    {
        
LogError("Query error: %s"sError);
        return;
    }
    
    
// Do some stuff..
    
    
delete hResult;


Last edited by jakesmokie; 08-25-2016 at 00:03.
jakesmokie is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-25-2016 , 04:07   Re: Memory leaks
Reply With Quote #2

Use sm_dump_handles command for finding leaks.
Kailo is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 08-25-2016 , 07:10   Re: Memory leaks
Reply With Quote #3

The code can be enhanced, but i don't see any error.

A few suggestions
  • Don't make your CallSomeMenu function public unless you need to
  • Use sizeof(sSteam) and sizeof(sQuery) instead of 31 and 255
  • Don't use DBPrio_* unless you know what it does and you need it
  • Don't try to delete the hResult variable, see here for more information
__________________

Last edited by Impact123; 08-25-2016 at 10:41.
Impact123 is offline
jakesmokie
Member
Join Date: Aug 2016
Old 08-25-2016 , 12:32   Re: Memory leaks
Reply With Quote #4

Thaks a lot, mates. If i use SQL_Query do i need to delete handle i guess?
jakesmokie is offline
jakesmokie
Member
Join Date: Aug 2016
Old 08-25-2016 , 12:33   Re: Memory leaks
Reply With Quote #5

Quote:
Originally Posted by kailo View Post
use sm_dump_handles command for finding leaks.
Спасибо за ответ

Last edited by jakesmokie; 08-25-2016 at 12:35.
jakesmokie is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-25-2016 , 12:40   Re: Memory leaks
Reply With Quote #6

Quote:
Originally Posted by jakesmokie View Post
Спасибо за ответ
oh, also when i got memory leak crash, SourceMod has done log in csgo/sourcemod_fatal.log

P.S. From rules:
Quote:
This is an English forum (other than a few specific, labeled subforums). If you're going to post in another language, also add the text in English, even if from online translator.

Last edited by Kailo; 08-25-2016 at 12:42.
Kailo is offline
jakesmokie
Member
Join Date: Aug 2016
Old 08-25-2016 , 12:53   Re: Memory leaks
Reply With Quote #7

Quote:
Originally Posted by Kailo View Post
oh, also when i got memory leak crash, SourceMod has done log in csgo/sourcemod_fatal.log

P.S. From rules:
Okay
jakesmokie 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 04:06.


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