From a4a031ad1bb46b5e9fa252f929d78fb2cba4d7bc Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Thu, 9 Jun 2022 20:57:35 +0300 Subject: [PATCH] fix memory leak with console --- src/client/component/console.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index d47761b8..2bb6826d 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -99,6 +99,8 @@ namespace console _RTL_CRITICAL_SECTION critSect; } s_wcd; + HBRUSH bk_brush; + HICON icon; HANDLE logo; @@ -120,7 +122,7 @@ namespace console case WM_CTLCOLORSTATIC: SetBkColor(reinterpret_cast(wparam), CONSOLE_BK_COLOR); SetTextColor(reinterpret_cast(wparam), CONSOLE_TEXT_COLOR); - return reinterpret_cast(CreateSolidBrush(CONSOLE_BK_COLOR)); + return reinterpret_cast(bk_brush); } return DefWindowProcA(hwnd, umsg, wparam, lparam); @@ -271,7 +273,7 @@ namespace console wndclass.lpfnWndProc = ConWndProc; wndclass.hInstance = hinstance; wndclass.hIcon = icon; - wndclass.hbrBackground = CreateSolidBrush(CONSOLE_BK_COLOR); + wndclass.hbrBackground = bk_brush; wndclass.hCursor = LoadCursorA(0, IDC_ARROW); wndclass.lpszMenuName = nullptr; wndclass.lpszClassName = class_name; @@ -469,6 +471,8 @@ namespace console { if (!console::is_enabled() || native::is_enabled()) return; + syscon::bk_brush = CreateSolidBrush(CONSOLE_BK_COLOR); + const utils::nt::library self; syscon::icon = LoadIconA(self.get_handle(), MAKEINTRESOURCEA(ID_ICON)); syscon::logo = LoadImageA(self.get_handle(), MAKEINTRESOURCEA(IMAGE_LOGO), 0, 0, 0, LR_COPYFROMRESOURCE); @@ -485,6 +489,8 @@ namespace console { if (!console::is_enabled() || native::is_enabled()) return; + if (syscon::bk_brush) DeleteObject(syscon::bk_brush); + if (syscon::icon) DestroyIcon(syscon::icon); if (syscon::logo) DeleteObject(syscon::logo); }