From 98008bcd4d7085d1b0170dfbd30a6ea14cff0611 Mon Sep 17 00:00:00 2001 From: harry Date: Sat, 4 Feb 2023 21:00:29 -0500 Subject: [PATCH] Fixed memory leak in Qt GUI when adding a new symbolic debug fails. Added error messaging to inform user why it failed. --- src/debugsymboltable.cpp | 11 +++++++++++ src/debugsymboltable.h | 2 ++ src/drivers/Qt/SymbolicDebug.cpp | 20 +++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/debugsymboltable.cpp b/src/debugsymboltable.cpp index b1f0e553..b65479ef 100644 --- a/src/debugsymboltable.cpp +++ b/src/debugsymboltable.cpp @@ -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; +} +//-------------------------------------------------------------- diff --git a/src/debugsymboltable.h b/src/debugsymboltable.h index 30c5a4ba..603c4e5c 100644 --- a/src/debugsymboltable.h +++ b/src/debugsymboltable.h @@ -171,6 +171,8 @@ class debugSymbolTable_t int deleteSymbolAtBankOffset( int bank, int ofs ); + const char *errorMessage(void); + private: std::map pageMap; FCEU::mutex *cs; diff --git a/src/drivers/Qt/SymbolicDebug.cpp b/src/drivers/Qt/SymbolicDebug.cpp index 1a9bf21e..a86fb434 100644 --- a/src/drivers/Qt/SymbolicDebug.cpp +++ b/src/drivers/Qt/SymbolicDebug.cpp @@ -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 {