[Debugger] Fix symbols memory leak

This commit is contained in:
shygoo 2019-12-27 12:48:55 -06:00
parent 37beacbe09
commit a2427459cb
2 changed files with 22 additions and 33 deletions

View File

@ -27,15 +27,8 @@ CSymbolTable::CSymbolTable(CDebuggerUI* debugger) :
CSymbolTable::~CSymbolTable()
{
if (m_SymFileBuffer != NULL)
{
free(m_SymFileBuffer);
}
if (m_SymFileParseBuffer != NULL)
{
free(m_SymFileParseBuffer);
}
delete[] m_SymFileBuffer;
delete[] m_SymFileParseBuffer;
}
symbol_type_info_t CSymbolTable::m_SymbolTypes[] = {
@ -108,23 +101,6 @@ CPath CSymbolTable::GetSymFilePath()
return symFilePath;
}
void CSymbolTable::ParserInit()
{
if (m_SymFileParseBuffer != NULL)
{
free(m_SymFileParseBuffer);
}
m_SymFileParseBuffer = (char*)malloc(m_SymFileSize + 1);
strcpy(m_SymFileParseBuffer, m_SymFileBuffer);
m_bHaveFirstToken = false;
}
void CSymbolTable::ParserDone()
{
free(m_SymFileParseBuffer);
}
void CSymbolTable::ParserFetchToken(const char* delim)
{
if (!m_bHaveFirstToken)
@ -172,17 +148,29 @@ void CSymbolTable::Load()
return;
}
if (m_SymFileBuffer != NULL)
{
delete[] m_SymFileBuffer;
}
if (m_SymFileParseBuffer != NULL)
{
delete[] m_SymFileParseBuffer;
}
m_SymFileSize = m_SymFileHandle.GetLength();
m_SymFileBuffer = (char*)malloc(m_SymFileSize + 1);
m_SymFileBuffer = new char[m_SymFileSize + 1];
m_SymFileParseBuffer = new char[m_SymFileSize + 1];
m_SymFileHandle.Read(m_SymFileBuffer, m_SymFileSize);
m_SymFileHandle.Close();
m_SymFileBuffer[m_SymFileSize] = '\0';
strcpy(m_SymFileParseBuffer, m_SymFileBuffer);
m_bHaveFirstToken = false;
symbol_parse_error_t errorCode = ERR_SUCCESS;
int lineNumber = 1;
ParserInit();
while (true)
{
uint32_t address = 0;
@ -254,8 +242,11 @@ void CSymbolTable::Load()
lineNumber++;
}
ParserDone();
free(m_SymFileBuffer);
delete[] m_SymFileParseBuffer;
m_SymFileParseBuffer = NULL;
delete[] m_SymFileBuffer;
m_SymFileBuffer = NULL;
switch (errorCode)
{

View File

@ -69,8 +69,6 @@ private:
char* m_SymFileParseBuffer;
bool m_bHaveFirstToken;
void ParserInit();
void ParserDone();
void ParserFetchToken(const char* delim);
public: