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

commit a206b55838d12db08ed5d616e01e067f1752cfac
Author:     Timo Kreuzer <[email protected]>
AuthorDate: Sat Dec 3 12:44:38 2022 +0200
Commit:     Timo Kreuzer <[email protected]>
CommitDate: Tue Dec 13 07:18:24 2022 +0100

    [WIN32K] Fix memory leak on failure in REGION_SetPolyPolygonRgn
---
 win32ss/gdi/ntgdi/region.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/win32ss/gdi/ntgdi/region.c b/win32ss/gdi/ntgdi/region.c
index 38bf3d377fa..2edf76d4a9f 100644
--- a/win32ss/gdi/ntgdi/region.c
+++ b/win32ss/gdi/ntgdi/region.c
@@ -3295,6 +3295,7 @@ REGION_SetPolyPolygonRgn(
     POINTBLOCK *tmpPtBlock;
     UINT numFullPtBlocks = 0;
     UINT poly, total;
+    BOOL bResult = FALSE;
 
     /* Check if iMode is valid */
     if ((iMode != ALTERNATE) && (iMode != WINDING))
@@ -3370,8 +3371,7 @@ REGION_SetPolyPolygonRgn(
                     if (tmpPtBlock == NULL)
                     {
                         DPRINT1("Can't alloc tmpPtBlock\n");
-                        ExFreePoolWithTag(pETEs, TAG_REGION);
-                        return FALSE;
+                        goto Cleanup;
                     }
 
                     curPtBlock->next = tmpPtBlock;
@@ -3426,8 +3426,7 @@ REGION_SetPolyPolygonRgn(
                         if (tmpPtBlock == NULL)
                         {
                             DPRINT1("Can't alloc tPB\n");
-                            ExFreePoolWithTag(pETEs, TAG_REGION);
-                            return FALSE;
+                            goto Cleanup;
                         }
                         curPtBlock->next = tmpPtBlock;
                         curPtBlock = tmpPtBlock;
@@ -3452,8 +3451,11 @@ REGION_SetPolyPolygonRgn(
         }
     }
 
-    REGION_FreeStorage(SLLBlock.next);
     REGION_PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, prgn);
+    bResult = TRUE;
+
+Cleanup:
+    REGION_FreeStorage(SLLBlock.next);
 
     for (curPtBlock = FirstPtBlock.next; numFullPtBlocks-- > 0;)
     {
@@ -3463,7 +3465,7 @@ REGION_SetPolyPolygonRgn(
     }
 
     ExFreePoolWithTag(pETEs, TAG_REGION);
-    return TRUE;
+    return bResult;
 }
 
 HRGN

Reply via email to