Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks #374

Open
tester0077 opened this issue Mar 12, 2024 · 4 comments
Open

Memory leaks #374

tester0077 opened this issue Mar 12, 2024 · 4 comments

Comments

@tester0077
Copy link

tester0077 commented Mar 12, 2024

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
Copy link
Author

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

@tester0077
Copy link
Author

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
Copy link
Author

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
Copy link
Collaborator

arvanus commented Apr 7, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants