https://git.reactos.org/?p=reactos.git;a=commitdiff;h=90432c1a4c2051a0a00a7780d04fb5555eca20e2

commit 90432c1a4c2051a0a00a7780d04fb5555eca20e2
Author:     Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com>
AuthorDate: Thu Jan 4 18:05:39 2024 +0900
Commit:     GitHub <nore...@github.com>
CommitDate: Thu Jan 4 18:05:39 2024 +0900

    [COMCTL32][USER32] EDIT & ListView & TreeView: Fix HRGN leaks (#6268)
    
    Based on KRosUser's memleak_comctl32.patch.
    JIRA issue: CORE-19405
    Fix HRGN handle leaks.
---
 dll/win32/comctl32/edit.c           | 4 +++-
 dll/win32/comctl32/listview.c       | 1 +
 dll/win32/comctl32/treeview.c       | 1 +
 win32ss/user/user32/controls/edit.c | 2 +-
 4 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/dll/win32/comctl32/edit.c b/dll/win32/comctl32/edit.c
index 67edb6b3e3f..5185605eb72 100644
--- a/dll/win32/comctl32/edit.c
+++ b/dll/win32/comctl32/edit.c
@@ -2568,7 +2568,7 @@ static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL 
can_undo, const WCHAR *lpsz_r
                                abs(es->selection_end - es->selection_start) - 
strl, hrgn);
                        strl = 0;
                        e = s;
-                       hrgn = CreateRectRgn(0, 0, 0, 0);
+                       SetRectRgn(hrgn, 0, 0, 0, 0);
                        if (!notify_parent(es, EN_MAXTEXT)) return;
                }
        }
@@ -3734,6 +3734,8 @@ static void EDIT_WM_NCPaint(HWND hwnd, HRGN region)
 
     /* Call default proc to get the scrollbars etc. also painted */
     DefWindowProcW (hwnd, WM_NCPAINT, (WPARAM)cliprgn, 0);
+    if (cliprgn != region)
+        DeleteObject(cliprgn);
 }
 
 /*********************************************************************
diff --git a/dll/win32/comctl32/listview.c b/dll/win32/comctl32/listview.c
index 5bd7e287a8b..f53bf9b7ff8 100644
--- a/dll/win32/comctl32/listview.c
+++ b/dll/win32/comctl32/listview.c
@@ -10817,6 +10817,7 @@ static BOOL LISTVIEW_NCPaint(const LISTVIEW_INFO 
*infoPtr, HRGN region)
 
     /* Call default proc to get the scrollbars etc. painted */
     DefWindowProcW (infoPtr->hwndSelf, WM_NCPAINT, (WPARAM)cliprgn, 0);
+    DeleteObject(cliprgn);
 
     return FALSE;
 }
diff --git a/dll/win32/comctl32/treeview.c b/dll/win32/comctl32/treeview.c
index e4a30d38103..d3066d72e2a 100644
--- a/dll/win32/comctl32/treeview.c
+++ b/dll/win32/comctl32/treeview.c
@@ -5482,6 +5482,7 @@ static BOOL TREEVIEW_NCPaint (const TREEVIEW_INFO 
*infoPtr, HRGN region, LPARAM
 
     /* Call default proc to get the scrollbars etc. painted */
     DefWindowProcW (infoPtr->hwnd, WM_NCPAINT, (WPARAM)cliprgn, 0);
+    DeleteObject(cliprgn);
 
     return TRUE;
 }
diff --git a/win32ss/user/user32/controls/edit.c 
b/win32ss/user/user32/controls/edit.c
index 21d2c24c64c..d48e8e3b034 100644
--- a/win32ss/user/user32/controls/edit.c
+++ b/win32ss/user/user32/controls/edit.c
@@ -2761,7 +2761,7 @@ static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL 
can_undo, LPCWSTR lpsz_replac
                                abs(es->selection_end - es->selection_start) - 
strl, hrgn);
                        strl = 0;
                        e = s;
-                       hrgn = CreateRectRgn(0, 0, 0, 0);
+                       SetRectRgn(hrgn, 0, 0, 0, 0);
                        if (!notify_parent(es, EN_MAXTEXT)) return;
                }
        }

Reply via email to