Skip to content

Commit 1d409e3

Browse files
authored
[EXPLORER] Fix handle leaks (reactos#8516)
JIRA issue: CORE-15616 JIRA issue: CORE-14382 The Explorer shell has multiple resource leaks causing handle exhaustion over extended use.
1 parent d2ae286 commit 1d409e3

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

base/shell/explorer/syspager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,15 @@ class CNotifyToolbar :
168168
void RefreshToolbarMetrics(BOOL bForceRefresh);
169169

170170
private:
171+
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
171172
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
172173
VOID SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wParam);
173174
LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
174175
LRESULT OnTooltipShow(INT uCode, LPNMHDR hdr, BOOL& bHandled);
175176

176177
public:
177178
BEGIN_MSG_MAP(CNotifyToolbar)
179+
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
178180
MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu)
179181
MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent)
180182
NOTIFY_CODE_HANDLER(TTN_SHOW, OnTooltipShow)
@@ -1031,6 +1033,17 @@ VOID CNotifyToolbar::ResizeImagelist()
10311033
SetButtonSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
10321034
}
10331035

1036+
LRESULT CNotifyToolbar::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
1037+
{
1038+
if (m_ImageList)
1039+
{
1040+
ImageList_Destroy(m_ImageList);
1041+
m_ImageList = NULL;
1042+
}
1043+
1044+
return 0;
1045+
}
1046+
10341047
LRESULT CNotifyToolbar::OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
10351048
{
10361049
bHandled = FALSE;

base/shell/explorer/taskswnd.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ class CHardErrorThread
276276
if (!m_hThread)
277277
{
278278
m_bThreadRunning = FALSE;
279-
CloseHandle(m_hThread);
280279
}
281280
}
282281
};
@@ -1557,6 +1556,13 @@ class CTaskSwitchWnd :
15571556

15581557
CloseThemeData(m_Theme);
15591558
DeleteAllTasks();
1559+
1560+
if (m_ImageList)
1561+
{
1562+
ImageList_Destroy(m_ImageList);
1563+
m_ImageList = NULL;
1564+
}
1565+
15601566
return TRUE;
15611567
}
15621568

base/shell/explorer/traywnd.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ class CTrayWindow :
533533
}
534534
}
535535

536-
CloseHandle(CreateThread(NULL, 0, s_RunFileDlgThread, this, 0, NULL));
536+
HANDLE hThread = CreateThread(NULL, 0, s_RunFileDlgThread, this, 0, NULL);
537+
if (hThread)
538+
CloseHandle(hThread);
537539
}
538540

539541
DWORD WINAPI TrayPropertiesThread()
@@ -587,7 +589,9 @@ class CTrayWindow :
587589
}
588590
}
589591

590-
CloseHandle(CreateThread(NULL, 0, s_TrayPropertiesThread, this, 0, NULL));
592+
HANDLE hThread = CreateThread(NULL, 0, s_TrayPropertiesThread, this, 0, NULL);
593+
if (hThread)
594+
CloseHandle(hThread);
591595
return NULL;
592596
}
593597

0 commit comments

Comments
 (0)