mariuz / flamerobin

FlameRobin is a database administration tool for Firebird RDBMS. Our goal is to build a tool that is: lightweight (small footprint, fast execution) cross-platform (Linux, Windows, Mac OS X, FreeBSD) dependent only on other Open Source software
http://flamerobin.org
MIT License
216 stars 67 forks source link

Memory leaks #374

Open tester0077 opened 8 months ago

tester0077 commented 8 months ago

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 commented 8 months ago

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

tester0077 commented 7 months ago

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 commented 7 months ago

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

arvanus commented 7 months ago

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!