diff --git a/reactos/subsystems/win32/win32k/ntuser/painting.c b/reactos/subsystems/win32/win32k/ntuser/painting.c index 1b43e12d3cb..af0b4262f47 100644 --- a/reactos/subsystems/win32/win32k/ntuser/painting.c +++ b/reactos/subsystems/win32/win32k/ntuser/painting.c @@ -166,27 +166,34 @@ IntGetNCUpdateRgn(PWINDOW_OBJECT Window, BOOL Validate) Window->UpdateRegion != (HRGN)1) { hRgnNonClient = NtGdiCreateRectRgn(0, 0, 0, 0); - hRgnWindow = IntCalcWindowRgn(Window, TRUE); /* * If region creation fails it's safe to fallback to whole * window region. */ - if (hRgnNonClient == NULL) { return (HRGN)1; } + hRgnWindow = IntCalcWindowRgn(Window, TRUE); + if (hRgnWindow == NULL) + { + NtGdiDeleteObject(hRgnNonClient); + return (HRGN)1; + } + RgnType = NtGdiCombineRgn(hRgnNonClient, Window->UpdateRegion, hRgnWindow, RGN_DIFF); if (RgnType == ERROR) { + NtGdiDeleteObject(hRgnWindow); NtGdiDeleteObject(hRgnNonClient); return (HRGN)1; } else if (RgnType == NULLREGION) { + NtGdiDeleteObject(hRgnWindow); NtGdiDeleteObject(hRgnNonClient); return NULL; }