mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-12 19:18:20 +00:00
Merge pull request #8279 from Robyt3/Base-FutureLogger-Leak
Add no-op logger to fix leak of `CFutureLogger` pending messages
This commit is contained in:
commit
b3bd831cde
|
@ -483,6 +483,19 @@ std::unique_ptr<ILogger> log_logger_windows_debugger()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class CLoggerNoOp : public ILogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Log(const CLogMessage *pMessage) override
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
};
|
||||||
|
std::unique_ptr<ILogger> log_logger_noop()
|
||||||
|
{
|
||||||
|
return std::make_unique<CLoggerNoOp>();
|
||||||
|
}
|
||||||
|
|
||||||
void CFutureLogger::Set(std::shared_ptr<ILogger> pLogger)
|
void CFutureLogger::Set(std::shared_ptr<ILogger> pLogger)
|
||||||
{
|
{
|
||||||
const CLockScope LockScope(m_PendingLock);
|
const CLockScope LockScope(m_PendingLock);
|
||||||
|
|
|
@ -210,6 +210,13 @@ std::unique_ptr<ILogger> log_logger_stdout();
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<ILogger> log_logger_windows_debugger();
|
std::unique_ptr<ILogger> log_logger_windows_debugger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup Log
|
||||||
|
*
|
||||||
|
* Logger which discards all logs.
|
||||||
|
*/
|
||||||
|
std::unique_ptr<ILogger> log_logger_noop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup Log
|
* @ingroup Log
|
||||||
*
|
*
|
||||||
|
|
|
@ -4499,9 +4499,9 @@ int main(int argc, const char **argv)
|
||||||
pSteam->ClearConnectAddress();
|
pSteam->ClearConnectAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
|
|
||||||
if(g_Config.m_Logfile[0])
|
if(g_Config.m_Logfile[0])
|
||||||
{
|
{
|
||||||
|
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
|
||||||
IOHANDLE Logfile = pStorage->OpenFile(g_Config.m_Logfile, Mode, IStorage::TYPE_SAVE_OR_ABSOLUTE);
|
IOHANDLE Logfile = pStorage->OpenFile(g_Config.m_Logfile, Mode, IStorage::TYPE_SAVE_OR_ABSOLUTE);
|
||||||
if(Logfile)
|
if(Logfile)
|
||||||
{
|
{
|
||||||
|
@ -4510,8 +4510,13 @@ int main(int argc, const char **argv)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_error("client", "failed to open '%s' for logging", g_Config.m_Logfile);
|
log_error("client", "failed to open '%s' for logging", g_Config.m_Logfile);
|
||||||
|
pFutureFileLogger->Set(log_logger_noop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pFutureFileLogger->Set(log_logger_noop());
|
||||||
|
}
|
||||||
|
|
||||||
// Register protocol and file extensions
|
// Register protocol and file extensions
|
||||||
#if defined(CONF_FAMILY_WINDOWS)
|
#if defined(CONF_FAMILY_WINDOWS)
|
||||||
|
|
|
@ -170,9 +170,9 @@ int main(int argc, const char **argv)
|
||||||
pConfigManager->SetReadOnly("sv_test_cmds", true);
|
pConfigManager->SetReadOnly("sv_test_cmds", true);
|
||||||
pConfigManager->SetReadOnly("sv_rescue", true);
|
pConfigManager->SetReadOnly("sv_rescue", true);
|
||||||
|
|
||||||
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
|
|
||||||
if(g_Config.m_Logfile[0])
|
if(g_Config.m_Logfile[0])
|
||||||
{
|
{
|
||||||
|
const int Mode = g_Config.m_Logappend ? IOFLAG_APPEND : IOFLAG_WRITE;
|
||||||
IOHANDLE Logfile = pStorage->OpenFile(g_Config.m_Logfile, Mode, IStorage::TYPE_SAVE_OR_ABSOLUTE);
|
IOHANDLE Logfile = pStorage->OpenFile(g_Config.m_Logfile, Mode, IStorage::TYPE_SAVE_OR_ABSOLUTE);
|
||||||
if(Logfile)
|
if(Logfile)
|
||||||
{
|
{
|
||||||
|
@ -181,8 +181,14 @@ int main(int argc, const char **argv)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_error("server", "failed to open '%s' for logging", g_Config.m_Logfile);
|
log_error("server", "failed to open '%s' for logging", g_Config.m_Logfile);
|
||||||
|
pFutureFileLogger->Set(log_logger_noop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pFutureFileLogger->Set(log_logger_noop());
|
||||||
|
}
|
||||||
|
|
||||||
auto pServerLogger = std::make_shared<CServerLogger>(pServer);
|
auto pServerLogger = std::make_shared<CServerLogger>(pServer);
|
||||||
pEngine->SetAdditionalLogger(pServerLogger);
|
pEngine->SetAdditionalLogger(pServerLogger);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue