AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Memory leak detected in plugin (https://forums.alliedmods.net/showthread.php?t=331538)

Lawyn 03-25-2021 07:59

Memory leak detected in plugin
 
I got this error after 10-15 minutes when server start. This error shutting down my plugin and all natives are in use by this.
Code:

L 03/25/2021 - 11:22:51: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "jailbreak_shop_remake.smx")
L 03/25/2021 - 11:22:51: [SM] Unloading plugin to free 26524 handles.
L 03/25/2021 - 11:22:51: [SM] Contact the author(s) of this plugin to correct this error.
L 03/25/2021 - 11:22:51: --------------------------------------------------------------------------
L 03/25/2021 - 11:22:51: Type        IQuery              |        Count        26522
L 03/25/2021 - 11:22:51: Type        IDatabase          |        Count        1
L 03/25/2021 - 11:22:51: Type        Timer              |        Count        1
L 03/25/2021 - 11:22:51: -- Approximately 0 bytes of memory are in use by (26524) Handles.

I used functions to get all i need from a database.
PHP Code:

int GetClientCredits2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT credite FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientRP2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT rp FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientJob2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT job FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientMats2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT materiale FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientDrugs2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT droguri FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientOre2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT ore FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientMinute2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT minute FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientSecunde2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT secunde FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientOreAdmin2(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT oreadmin FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientSkillMats(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT skillmats FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientSkillDrugs(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT skilldrugs FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

int GetClientSkillAsasin(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT skillasasin FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd0); CloseHandle(asd);}
    
CloseHandle(asd);
}

void SetClientOre2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', ore='%i' WHERE steamid='%s'"namesteamidsumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientJob2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', job='%i' WHERE steamid='%s'"namesteamidsumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientMinute2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', minute='%i' WHERE steamid='%s'"namesteamidsumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientSecunde2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', secunde='%i' WHERE steamid='%s'"namesteamidsumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientCredits2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', credite='%i' WHERE steamid='%s'"namesteamidGetClientCredits2(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientMats2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', materiale='%i' WHERE steamid='%s'"namesteamidGetClientMats2(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientDrugs2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', droguri='%i' WHERE steamid='%s'"namesteamidGetClientDrugs2(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientRP2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', rp='%i' WHERE steamid='%s'"namesteamidGetClientRP2(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientOreAdmin2(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', oreadmin='%i' WHERE steamid='%s'"namesteamidsumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientSkillDrugs(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', skilldrugs='%i' WHERE steamid='%s'"namesteamidGetClientSkillDrugs(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientSkillMats(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', skillmats='%i' WHERE steamid='%s'"namesteamidGetClientSkillMats(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);
}

void SetClientSkillAsasin(int clientint suma)
{
    
char steamid[55], qwe[256], name[MAX_NAME_LENGTH];
    
GetClientName(clientnamesizeof(name));
    
GetClientAuthString(clientsteamidsizeof(steamid));
    
Format(qwesizeof(qwe), "UPDATE shopp SET nume='%s', steamid='%s', skillasasin='%i' WHERE steamid='%s'"namesteamidGetClientSkillAsasin(client) + sumasteamid);
    
Handle asd SQL_Query(DBqwe);
    
CloseHandle(asd);



Bacardi 03-25-2021 09:22

Re: Memory leak detected in plugin
 
You maybe need fetch result into variable, close handle, then return variable (as result or 0, false, etc. etc.)
Quote:

Originally Posted by Lawyn (Post 2741736)
Code:

...
        Handle asd = SQL_Query(DB, qwe);
        if (asd != INVALID_HANDLE && SQL_FetchRow(asd)) { return SQL_FetchInt(asd, 0); CloseHandle(asd);}
        CloseHandle(asd);
...



Lawyn 03-25-2021 14:49

Re: Memory leak detected in plugin
 
Quote:

Originally Posted by Bacardi (Post 2741749)
You maybe need fetch result into variable, close handle, then return variable (as result or 0, false, etc. etc.)

It doesn`t work

Bacardi 03-25-2021 15:55

Re: Memory leak detected in plugin
 
Show your code

Marttt 03-25-2021 17:14

Re: Memory leak detected in plugin
 
try changing the lines to:

PHP Code:

...
    
int value;
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { value SQL_FetchInt(asd0); }
    
CloseHandle(asd);
    return 
value;
... 


Lawyn 03-26-2021 13:19

Re: Memory leak detected in plugin
 
Quote:

Originally Posted by Bacardi (Post 2741812)
Show your code

PHP Code:

int GetClientSkillDrugs(int client)
{
    
char steamid[55], qwe[256];
    
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid));
    
Format(qwesizeof(qwe), "SELECT skilldrugs FROM shopp WHERE steamid='%s'"steamid);
    
Handle asd SQL_Query(DBqwe);
    
int suma = -1;
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { suma SQL_FetchInt(asd0); }
    
CloseHandle(asd); asd INVALID_HANDLE;
    return 
suma;


This work better !

Lawyn 03-26-2021 13:19

Re: Memory leak detected in plugin
 
Quote:

Originally Posted by Marttt (Post 2741824)
try changing the lines to:

PHP Code:

...
    
int value;
    if (
asd != INVALID_HANDLE && SQL_FetchRow(asd)) { value SQL_FetchInt(asd0); }
    
CloseHandle(asd);
    return 
value;
... 


Thx man, worked!


All times are GMT -4. The time now is 06:53.

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