Fixed memory leak in Qt GUI when adding a new symbolic debug fails. Added error messaging to inform user why it failed.

This commit is contained in:
harry 2023-02-04 21:00:29 -05:00
parent fb75b34b1d
commit 98008bcd4d
3 changed files with 30 additions and 3 deletions

View File

@ -19,6 +19,7 @@ extern FCEUGI *GameInfo;
debugSymbolTable_t debugSymbolTable;
static char dbgSymTblErrMsg[256] = {0};
//--------------------------------------------------------------
// debugSymbolPage_t
//--------------------------------------------------------------
@ -41,10 +42,12 @@ int debugSymbolPage_t::addSymbol( debugSymbol_t*sym )
// Check if symbol already is loaded by that name or offset
if ( symMap.count( sym->offset() ) )
{
snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: symbol offset 0x%04x already has an entry on page:%i\n", sym->offset(), pageNum );
return -1;
}
if ( (sym->name().size() > 0) && symNameMap.count( sym->name() ) )
{
snprintf( dbgSymTblErrMsg, sizeof(dbgSymTblErrMsg), "Error: symbol name '%s' already exists on page:%i\n", sym->name().c_str(), pageNum );
return -1;
}
@ -230,6 +233,8 @@ void debugSymbolPage_t::print(void)
debugSymbolTable_t::debugSymbolTable_t(void)
{
cs = new FCEU::mutex();
dbgSymTblErrMsg[0] = 0;
}
//--------------------------------------------------------------
debugSymbolTable_t::~debugSymbolTable_t(void)
@ -765,3 +770,9 @@ void debugSymbolTable_t::print(void)
page->print();
}
}
//--------------------------------------------------------------
const char *debugSymbolTable_t::errorMessage(void)
{
return dbgSymTblErrMsg;
}
//--------------------------------------------------------------

View File

@ -171,6 +171,8 @@ class debugSymbolTable_t
int deleteSymbolAtBankOffset( int bank, int ofs );
const char *errorMessage(void);
private:
std::map <int, debugSymbolPage_t*> pageMap;
FCEU::mutex *cs;

View File

@ -35,6 +35,7 @@
#include "Qt/fceuWrapper.h"
#include "Qt/SymbolicDebug.h"
#include "Qt/ConsoleUtilities.h"
#include "Qt/ConsoleWindow.h"
//--------------------------------------------------------------
@ -826,8 +827,14 @@ int SymbolEditWindow::exec(void)
{
sym = new debugSymbol_t(a);
debugSymbolTable.addSymbolAtBankOffset( b, a, sym );
if ( debugSymbolTable.addSymbolAtBankOffset( b, a, sym ) )
{
if (consoleWindow)
{
consoleWindow->QueueErrorMsgWindow( debugSymbolTable.errorMessage() );
}
delete sym;
}
isNew = true;
}
sym->setOffset(a);
@ -861,7 +868,14 @@ int SymbolEditWindow::exec(void)
sym = new debugSymbol_t( addr, nameEntry->text().toStdString().c_str(),
commentEntry->toPlainText().toStdString().c_str());
debugSymbolTable.addSymbolAtBankOffset( bank, addr, sym );
if ( debugSymbolTable.addSymbolAtBankOffset( bank, addr, sym ) )
{
if (consoleWindow)
{
consoleWindow->QueueErrorMsgWindow( debugSymbolTable.errorMessage() );
}
delete sym;
}
}
else
{