-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Description of the Issue
In BabyGrid.cpp, inside the GridProc function, three fonts (g_hfontbody, g_hfontheader, g_hfonttitle) are created:
LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// ...
case WM_CREATE:
{
CREATESTRUCT* lpcs = (LPCREATESTRUCT)lParam;
HINSTANCE hInst = lpcs->hInstance;
int BG_GridIndex = AddGrid(GetMenu(hWnd));
if (CountGrids() == 1)
{
g_hfontbody = CreateFont(16, 0, 0, 0,
100,
FALSE,
FALSE, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
0,
0,
L"MS Shell Dlg");
g_hfontheader = CreateFont(18, 0, 0, 0, FW_HEAVY, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 0, 0, L"MS Shell Dlg");
g_hfonttitle = CreateFont(20, 0, 0, 0, FW_HEAVY, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 0, 0, L"MS Shell Dlg");
}
}
// ...
}
}
When the BabyGrid window is destroyed, there is code intended to delete these objects:
LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// ...
case WM_DESTROY:
{
if (CountGrids() == 0)
{
DeleteObject(g_hfontbody);
DeleteObject(g_hfontheader);
DeleteObject(g_hfonttitle);
}
}
// ...
}
}
However, at that point the condition if (CountGrids() == 0) is not met - it remains CountGrids() == 1, meaning DeleteObject is never called.
As a result, these three font objects are not explicitly freed until the ShortcutMapper window itself is destroyed, causing a memory leak.
Steps To Reproduce
- Open the "Shortcut Mapper" window.
- Close it.
- Repeat the above steps.
Current Behavior
The three fonts (g_hfontbody, g_hfontheader, g_hfonttitle) are not properly released when closing the window, resulting in a memory leak.
Expected Behavior
It should call DeleteObject before the BabyGrid window is destroyed.
Debug Information
noneAnything else?
No response
Reactions are currently unavailable