Skip to content

Commit 9428164

Browse files
committed
Fix some more MTA server crash handler issues:
- Use delete[] instead of delete for char array in CExceptionInformation_Impl destructor - Use nothrow new with null check in HandleExceptionGlobal to avoid throwing when heap is corrupt - Replace ctime with localtime_s and strftime to avoid static buffer reuse
1 parent b9ff050 commit 9428164

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Server/core/CCrashHandler.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static SString ms_strDumpPath;
4747

4848
#ifdef WIN32
4949
#include <ctime>
50+
#include <new>
5051
#include <tchar.h>
5152
#include <dbghelp.h>
5253

@@ -180,7 +181,12 @@ void CCrashHandler::HandleExceptionGlobal(int iSig)
180181
long WINAPI CCrashHandler::HandleExceptionGlobal(_EXCEPTION_POINTERS* pException)
181182
{
182183
// Create the exception information class
183-
CExceptionInformation_Impl* pExceptionInformation = new CExceptionInformation_Impl;
184+
CExceptionInformation_Impl* pExceptionInformation = new (std::nothrow) CExceptionInformation_Impl;
185+
if (!pExceptionInformation)
186+
{
187+
TerminateProcess(GetCurrentProcess(), 1);
188+
return EXCEPTION_CONTINUE_SEARCH;
189+
}
184190
pExceptionInformation->Set(pException->ExceptionRecord->ExceptionCode, pException);
185191

186192
// Write the dump
@@ -286,7 +292,12 @@ void CCrashHandler::DumpMiniDump(_EXCEPTION_POINTERS* pException, CExceptionInfo
286292

287293
SString strInfo;
288294
strInfo += SString("Version = %s\n", strMTAVersionFull.c_str());
289-
strInfo += SString("Time = %s", ctime(&timeTemp));
295+
296+
char szTimeBuf[64];
297+
struct tm tmLocal;
298+
localtime_s(&tmLocal, &timeTemp);
299+
strftime(szTimeBuf, sizeof(szTimeBuf), "%c\n", &tmLocal);
300+
strInfo += SString("Time = %s", szTimeBuf);
290301

291302
strInfo += SString("Module = %s\n", pExceptionInformation->GetModulePathName());
292303

Server/core/CExceptionInformation_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CExceptionInformation_Impl::CExceptionInformation_Impl()
4444
CExceptionInformation_Impl::~CExceptionInformation_Impl()
4545
{
4646
if (m_szModulePathName)
47-
delete m_szModulePathName;
47+
delete[] m_szModulePathName;
4848
}
4949

5050
void CExceptionInformation_Impl::Set(unsigned int iCode, _EXCEPTION_POINTERS* pException)

0 commit comments

Comments
 (0)