flamerobin icon indicating copy to clipboard operation
flamerobin copied to clipboard

Memory leaks

Open tester0077 opened this issue 1 year ago • 4 comments

As part of my recent efforts to bring an old app of mine up-to-date and use the latest Firebird features,I ended up setting up a MSVC 2022 environment with wxWidgets 2.2. Part of my earlier work was to include some of memory leak detection features available in MSVC.

When I first compiled and ran the FlameRobin code I noticed a good number of memory leaks reported when the app was shut down. As I had a couple of hours time to instrument my test setup, I think I found at least some of the places where memory is allocated, but apparently not freed on exit. Note: to avoid issues with line numbers, I will omit them in the hope that the rest of the information will provide enough context.

Since I simply don't know enough about the FR code, I will simply report the locations here and hope somebody more familiar with the code can find a suitable place to release the memory allocated with new at:


metadata - database.cpp 
void Database::loadTimezones()
{
      tzItm = new TimezoneInfo;       //  - leak
}
---------------------------------
config - localSettingd.cpp

LocalSettings::LocalSettings()
{
    locale = new wxLocale();        //---  leak
}

LocalSettings::~LocalSettings()
{
    locale = new wxLocale();        //--- leak
}

tester0077 avatar Mar 12 '24 02:03 tester0077

If anyone can fix the "shouting" text, please do so TIA

tester0077 avatar Mar 12 '24 14:03 tester0077

This issue can be resolved by adding a line to delete the allocation on exit from each of the functions in src\config\LocalSettings.cpp

LocalSettings::LocalSettings() { wxLocale* locale; locale = new wxLocale(); //--- leak if (config().getUseLocalConfig()) locale->Init(wxLANGUAGE_DEFAULT); else locale->Init(wxLANGUAGE_ENGLISH); delete locale; // <-- fix }

LocalSettings::~LocalSettings() { wxLocale* locale; locale = new wxLocale(); //--- leak if (config().getUseLocalConfig()) locale->Init(wxLANGUAGE_DEFAULT); else locale->Init(wxLANGUAGE_ENGLISH); delete locale; // fix }

void LocalSettings::setDataBaseLenguage() { wxLocale* locale; locale = new wxLocale(); //--- leak locale->Init(wxLANGUAGE_ENGLISH); delete locale; // fix }

tester0077 avatar Apr 01 '24 02:04 tester0077

A second leak in database.cpp @ line #2308++ can be fixed with

tzItm = new TimezoneInfo; // todo - leak tzItm->id = tzId; tzItm->name = std2wxIdentifier(tzName, converter); timezonesM.push_back(tzItm); delete tzItm; // fix

tester0077 avatar Apr 01 '24 18:04 tester0077

Hello @tester0077 Can you describe your project changes to detect memory leaks? In pascal I use regularly, but was reading for C++ and found to be a little pain to do it, don't know if this are the same steps you did. Or at least fork and commit your project so I can take a look (don't need to push merge request, just let me know here) Thanks!

arvanus avatar Apr 07 '24 17:04 arvanus