From 0d5ed410c14fe4bc4a748d19de879cc2ee25e203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Mon, 24 Mar 2003 22:49:54 +0000 Subject: [PATCH] Fix GDI handle leaks svn path=/trunk/; revision=4425 --- reactos/subsys/win32k/eng/mouse.c | 54 +++++++++++++------------ reactos/subsys/win32k/objects/bitmaps.c | 9 +++-- reactos/subsys/win32k/objects/dc.c | 4 +- reactos/subsys/win32k/objects/dib.c | 2 + 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/reactos/subsys/win32k/eng/mouse.c b/reactos/subsys/win32k/eng/mouse.c index 5665c000774..47b3805fb96 100644 --- a/reactos/subsys/win32k/eng/mouse.c +++ b/reactos/subsys/win32k/eng/mouse.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: mouse.c,v 1.20 2003/03/11 00:21:41 gvg Exp $ +/* $Id: mouse.c,v 1.21 2003/03/24 22:49:54 gvg Exp $ * * PROJECT: ReactOS kernel * PURPOSE: Mouse @@ -320,37 +320,41 @@ EnableMouse(HDC hDisplayDC) SIZEL MouseSize; RECTL MouseRect; - dc = DC_HandleToPtr(hDisplayDC); - if( dc ){ - SurfObj = (PSURFOBJ)AccessUserObject((ULONG) dc->Surface); - SurfGDI = (PSURFGDI)AccessInternalObject((ULONG) dc->Surface); - DC_ReleasePtr( hDisplayDC ); + if( hDisplayDC ) + { + dc = DC_HandleToPtr(hDisplayDC); + SurfObj = (PSURFOBJ)AccessUserObject((ULONG) dc->Surface); + SurfGDI = (PSURFGDI)AccessInternalObject((ULONG) dc->Surface); + DC_ReleasePtr( hDisplayDC ); - /* Create the default mouse cursor. */ - mouse_width = 32; - mouse_height = 32; - MouseSize.cx = 32; - MouseSize.cy = 64; - hMouseSurf = EngCreateBitmap(MouseSize, 4, BMF_1BPP, BMF_TOPDOWN, DefaultCursor); - MouseSurf = (PSURFOBJ)AccessUserObject((ULONG) hMouseSurf); + /* Create the default mouse cursor. */ + mouse_width = 32; + mouse_height = 32; + MouseSize.cx = 32; + MouseSize.cy = 64; + hMouseSurf = EngCreateBitmap(MouseSize, 4, BMF_1BPP, BMF_TOPDOWN, DefaultCursor); + MouseSurf = (PSURFOBJ)AccessUserObject((ULONG) hMouseSurf); - /* Tell the display driver to set the pointer shape. */ + /* Tell the display driver to set the pointer shape. */ #if 0 - mouse_x = SurfObj->sizlBitmap.cx / 2; - mouse_y = SurfObj->sizlBitmap.cy / 2; + mouse_x = SurfObj->sizlBitmap.cx / 2; + mouse_y = SurfObj->sizlBitmap.cy / 2; #else - mouse_x = 320; - mouse_y = 240; + mouse_x = 320; + mouse_y = 240; #endif - PointerStatus = SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, - 0, 0, mouse_x, mouse_y, &MouseRect, - SPS_CHANGE); + PointerStatus = SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, + 0, 0, mouse_x, mouse_y, &MouseRect, + SPS_CHANGE); - MouseEnabled = (SPS_ACCEPT_EXCLUDE == PointerStatus || - SPS_ACCEPT_NOEXCLUDE == PointerStatus); + MouseEnabled = (SPS_ACCEPT_EXCLUDE == PointerStatus || + SPS_ACCEPT_NOEXCLUDE == PointerStatus); + + EngDeleteSurface(hMouseSurf); } - else{ - MouseEnabled = FALSE; + else + { + MouseEnabled = FALSE; } } diff --git a/reactos/subsys/win32k/objects/bitmaps.c b/reactos/subsys/win32k/objects/bitmaps.c index aa63a089400..9a556907855 100644 --- a/reactos/subsys/win32k/objects/bitmaps.c +++ b/reactos/subsys/win32k/objects/bitmaps.c @@ -27,7 +27,7 @@ BOOL STDCALL W32kBitBlt(HDC hDCDest, POINTL SourcePoint; PBITMAPOBJ DestBitmapObj; PBITMAPOBJ SrcBitmapObj; - BOOL Status, SurfDestAlloc, SurfSrcAlloc; + BOOL Status, SurfDestAlloc, SurfSrcAlloc, XlateAlloc; PPALOBJ DCLogPal; PPALGDI PalDestGDI, PalSourceGDI; PXLATEOBJ XlateObj = NULL; @@ -49,6 +49,7 @@ BOOL STDCALL W32kBitBlt(HDC hDCDest, SurfDestAlloc = FALSE; SurfSrcAlloc = FALSE; + XlateAlloc = FALSE; // Determine surfaces to be used in the bitblt SurfDest = (PSURFOBJ)AccessUserObject(DCDest->Surface); @@ -83,14 +84,16 @@ BOOL STDCALL W32kBitBlt(HDC hDCDest, PalSourceGDI = (PPALGDI)AccessInternalObject(SourcePalette); XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestGDI->Mode, PalSourceGDI->Mode, DestPalette, SourcePalette); + XlateAlloc = TRUE; } // Perform the bitblt operation Status = IntEngBitBlt(SurfDest, SurfSrc, NULL, NULL, XlateObj, &DestRect, &SourcePoint, NULL, NULL, NULL, ROP); - if(SurfDestAlloc == TRUE) ExFreePool(SurfDest); - if(SurfSrcAlloc == TRUE) ExFreePool(SurfSrc); + if (XlateAlloc) EngDeleteXlate(XlateObj); + if (SurfDestAlloc) ExFreePool(SurfDest); + if (SurfSrcAlloc) ExFreePool(SurfSrc); DC_ReleasePtr(hDCDest); DC_ReleasePtr(hDCSrc); diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index b3c694be318..ac3401a2a95 100644 --- a/reactos/subsys/win32k/objects/dc.c +++ b/reactos/subsys/win32k/objects/dc.c @@ -1,4 +1,4 @@ -/* $Id: dc.c,v 1.51 2003/03/22 23:57:32 gvg Exp $ +/* $Id: dc.c,v 1.52 2003/03/24 22:49:54 gvg Exp $ * * DC.C - Device context functions * @@ -497,6 +497,7 @@ BOOL STDCALL W32kDeleteDC(HDC DCHandle) BITMAPOBJ_ReleasePtr(DCToDelete->w.hBitmap); if (DCToDelete->w.flags & DC_MEMORY) { + EngDeleteSurface (DCToDelete->Surface); W32kDeleteObject (DCToDelete->w.hFirstBitmap); } } @@ -1082,6 +1083,7 @@ HGDIOBJ STDCALL W32kSelectObject(HDC hDC, HGDIOBJ hGDIObj) objOrg = (HGDIOBJ)dc->w.hBitmap; /* Release the old bitmap, lock the new one and convert it to a SURF */ + EngDeleteSurface(dc->Surface); BITMAPOBJ_ReleasePtr(objOrg); dc->w.hBitmap = hGDIObj; pb = BITMAPOBJ_HandleToPtr(hGDIObj); diff --git a/reactos/subsys/win32k/objects/dib.c b/reactos/subsys/win32k/objects/dib.c index 93a0af4caa3..869cad62e8a 100644 --- a/reactos/subsys/win32k/objects/dib.c +++ b/reactos/subsys/win32k/objects/dib.c @@ -154,6 +154,8 @@ INT STDCALL W32kSetDIBits(HDC hDC, } // Clean up + EngDeleteXlate(XlateObj); + EngDeletePalette(DIB_Palette); EngDeleteSurface(SourceBitmap); EngDeleteSurface(DestBitmap);