Raised This Month: $32 Target: $400
 8% 

Solved [CSGO && DISCORD] Discord Server to Game Server Chat Memory Leak


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cruze
Veteran Member
Join Date: May 2017
Old 07-02-2020 , 15:10   [CSGO && DISCORD] Discord Server to Game Server Chat Memory Leak
Reply With Quote #1

PHP Code:
/* Code taken from Discord Server Manager of Nexd */

#include <sourcemod>
#include <multicolors>
#include <discord>

#define ChatRelayChannelID ""
#define BOT_TOKEN ""
#define DiscordTag "[DISCORD]"

DiscordBot Bot;

public 
void OnConfigsExecuted()
{
    
KillBot();
    
CreateBot();
}

public 
void GuildList(DiscordBot bawtchar[] idchar[] namechar[] iconbool ownerint permissions, const bool listen)
{
    
Bot.GetGuildChannels(idChannelListINVALID_FUNCTIONlisten);
}

public 
void ChannelList(DiscordBot bawt, const char[] guildDiscordChannel Channel, const bool listen)
{
    if(
StrEqual(BOT_TOKEN"") || StrEqual(ChatRelayChannelID""))
    {
        return;
    }
    
char id[20];
    
Channel.GetID(idsizeof(id));
    if(
strlen(ChatRelayChannelID) > 10)
    {
        if(
StrEqual(idChatRelayChannelID))
        {
            if(
Bot.IsListeningToChannel(Channel))
            {
                
Bot.StopListeningToChannel(Channel);
            }
            
Bot.StartListeningToChannel(ChannelChatRelayReceived);
        }
    }
}

public 
void ChatRelayReceived(DiscordBot bawtDiscordChannel channelDiscordMessage discordmessage)
{
    if(
discordmessage.GetAuthor().IsBot()) return;

    
char message[512];
    
char userName[32], discriminator[6];
    
discordmessage.GetContent(messagesizeof(message));
    
discordmessage.GetAuthor().GetUsername(userNamesizeof(userName));
    
discordmessage.GetAuthor().GetDiscriminator(discriminatorsizeof(discriminator));

    
CPrintToChatAll("%s{purple} %s#%s{default}: %s"DiscordTaguserNamediscriminatormessage);
}

stock void CreateBot(bool guilds truebool listen true)
{
    if(
StrEqual(BOT_TOKEN"") || StrEqual(ChatRelayChannelID""))
    {
        return;
    }
    
Bot = new DiscordBot(BOT_TOKEN);
    if(
guilds)
    {
        
Bot.GetGuilds(GuildList_listen);
    }
}

stock void KillBot()
{
    
delete Bot;

Code:
L 07/02/2020 - 09:14:14: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "thisplugin")
L 07/02/2020 - 09:14:14: [SM] Unloading plugin to free 14593 handles.
L 07/02/2020 - 09:14:14: [SM] Contact the author(s) of this plugin to correct this error.
L 07/02/2020 - 09:14:14: --------------------------------------------------------------------------
L 07/02/2020 - 09:14:14: Type	DataPack            |	Count	35
L 07/02/2020 - 09:14:14: Type	CellArray           |	Count	35
L 07/02/2020 - 09:14:14: Type	JanssonObject       |	Count	14523
L 07/02/2020 - 09:14:14: -- Approximately 1260 bytes of memory are in use by (14593) Handles.

L 07/02/2020 - 09:14:14: [SM] Exception reported: Memory leak
L 07/02/2020 - 09:14:14: [SM] Blaming: discord_api.smx
L 07/02/2020 - 09:14:14: [SM] Call stack trace:
L 07/02/2020 - 09:14:14: [SM]   [0] json_object_get
L 07/02/2020 - 09:14:14: [SM]   [1] Line 18, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/stocks.inc::JsonObjectGetString
L 07/02/2020 - 09:14:14: [SM]   [2] Line 23, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/channel.inc::DiscordChannel.GetID
L 07/02/2020 - 09:14:14: [SM]   [3] Line 68, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/bot.inc::DiscordBot.IsListeningToChannelID
L 07/02/2020 - 09:14:14: [SM]   [4] Line 106, discord/ListenToChannel.sp::OnGetMessage_Data
L 07/02/2020 - 09:14:14: [SM]   [6] SteamWorks_GetHTTPResponseBodyCallback
L 07/02/2020 - 09:14:14: [SM]   [7] Line 74, discord/ListenToChannel.sp::OnGetMessage
L 07/02/2020 - 09:14:14: [SM] Exception reported: Could not create <Object> handle.
L 07/02/2020 - 09:14:14: [SM] Blaming: discord_api.smx
L 07/02/2020 - 09:14:14: [SM] Call stack trace:
L 07/02/2020 - 09:14:14: [SM]   [0] json_object_get
L 07/02/2020 - 09:14:14: [SM]   [1] Line 18, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/stocks.inc::JsonObjectGetString
L 07/02/2020 - 09:14:14: [SM]   [2] Line 23, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/channel.inc::DiscordChannel.GetID
L 07/02/2020 - 09:14:14: [SM]   [3] Line 68, sourcemod-discord-master\sourcemod-discord-master\scripting\include\discord/bot.inc::DiscordBot.IsListeningToChannelID
L 07/02/2020 - 09:14:14: [SM]   [4] Line 106, discord/ListenToChannel.sp::OnGetMessage_Data
L 07/02/2020 - 09:14:14: [SM]   [6] SteamWorks_GetHTTPResponseBodyCallback
L 07/02/2020 - 09:14:14: [SM]   [7] Line 74, discord/ListenToChannel.sp::OnGetMessage
Any heads up would be appreciated. Every thing works though.
Edit: This is just snippet of whole code. This issue comes up only when using this part of code so...
Edit2: This fixed the issue again took help from nexd's plugin xd
Code:
stock void KillBot()
{
	if(Bot)
	{
		Bot.StopListeningToChannels();
		Bot.StopListening();
	}
	delete Bot;
}
__________________
Taking paid private requests! Contact me

Last edited by Cruze; 07-03-2020 at 05:45.
Cruze is offline
Desktop
AlliedModders Donor
Join Date: Sep 2009
Location: C:\Users\Default\
Old 07-02-2020 , 15:20   Re: [CSGO && DISCORD] Discord Server to Game Server Chat Memory Leak
Reply With Quote #2

You should delete each JSONObject everytime you stop using it, since it's Handle based and Handles are not automatically closed.
__________________
Massive Infection:: Piu-Games
Desktop is offline
Cruze
Veteran Member
Join Date: May 2017
Old 07-03-2020 , 05:46   Re: [CSGO && DISCORD] Discord Server to Game Server Chat Memory Leak
Reply With Quote #3

Quote:
Originally Posted by Desktop View Post
You should delete each JSONObject everytime you stop using it, since it's Handle based and Handles are not automatically closed.
Thanks, that really helped. I knew it was open handles that caused the issue but couldn't find open handles before.
__________________
Taking paid private requests! Contact me
Cruze 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 12:00.


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