Fix GDI handle leaks

svn path=/trunk/; revision=4425
This commit is contained in:
Gé van Geldorp 2003-03-24 22:49:54 +00:00
parent a3437854ba
commit 0d5ed410c1
4 changed files with 40 additions and 29 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * PROJECT: ReactOS kernel
* PURPOSE: Mouse * PURPOSE: Mouse
@ -320,37 +320,41 @@ EnableMouse(HDC hDisplayDC)
SIZEL MouseSize; SIZEL MouseSize;
RECTL MouseRect; RECTL MouseRect;
dc = DC_HandleToPtr(hDisplayDC); if( hDisplayDC )
if( dc ){ {
SurfObj = (PSURFOBJ)AccessUserObject((ULONG) dc->Surface); dc = DC_HandleToPtr(hDisplayDC);
SurfGDI = (PSURFGDI)AccessInternalObject((ULONG) dc->Surface); SurfObj = (PSURFOBJ)AccessUserObject((ULONG) dc->Surface);
DC_ReleasePtr( hDisplayDC ); SurfGDI = (PSURFGDI)AccessInternalObject((ULONG) dc->Surface);
DC_ReleasePtr( hDisplayDC );
/* Create the default mouse cursor. */ /* Create the default mouse cursor. */
mouse_width = 32; mouse_width = 32;
mouse_height = 32; mouse_height = 32;
MouseSize.cx = 32; MouseSize.cx = 32;
MouseSize.cy = 64; MouseSize.cy = 64;
hMouseSurf = EngCreateBitmap(MouseSize, 4, BMF_1BPP, BMF_TOPDOWN, DefaultCursor); hMouseSurf = EngCreateBitmap(MouseSize, 4, BMF_1BPP, BMF_TOPDOWN, DefaultCursor);
MouseSurf = (PSURFOBJ)AccessUserObject((ULONG) hMouseSurf); 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 #if 0
mouse_x = SurfObj->sizlBitmap.cx / 2; mouse_x = SurfObj->sizlBitmap.cx / 2;
mouse_y = SurfObj->sizlBitmap.cy / 2; mouse_y = SurfObj->sizlBitmap.cy / 2;
#else #else
mouse_x = 320; mouse_x = 320;
mouse_y = 240; mouse_y = 240;
#endif #endif
PointerStatus = SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, PointerStatus = SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL,
0, 0, mouse_x, mouse_y, &MouseRect, 0, 0, mouse_x, mouse_y, &MouseRect,
SPS_CHANGE); SPS_CHANGE);
MouseEnabled = (SPS_ACCEPT_EXCLUDE == PointerStatus || MouseEnabled = (SPS_ACCEPT_EXCLUDE == PointerStatus ||
SPS_ACCEPT_NOEXCLUDE == PointerStatus); SPS_ACCEPT_NOEXCLUDE == PointerStatus);
EngDeleteSurface(hMouseSurf);
} }
else{ else
MouseEnabled = FALSE; {
MouseEnabled = FALSE;
} }
} }

View file

@ -27,7 +27,7 @@ BOOL STDCALL W32kBitBlt(HDC hDCDest,
POINTL SourcePoint; POINTL SourcePoint;
PBITMAPOBJ DestBitmapObj; PBITMAPOBJ DestBitmapObj;
PBITMAPOBJ SrcBitmapObj; PBITMAPOBJ SrcBitmapObj;
BOOL Status, SurfDestAlloc, SurfSrcAlloc; BOOL Status, SurfDestAlloc, SurfSrcAlloc, XlateAlloc;
PPALOBJ DCLogPal; PPALOBJ DCLogPal;
PPALGDI PalDestGDI, PalSourceGDI; PPALGDI PalDestGDI, PalSourceGDI;
PXLATEOBJ XlateObj = NULL; PXLATEOBJ XlateObj = NULL;
@ -49,6 +49,7 @@ BOOL STDCALL W32kBitBlt(HDC hDCDest,
SurfDestAlloc = FALSE; SurfDestAlloc = FALSE;
SurfSrcAlloc = FALSE; SurfSrcAlloc = FALSE;
XlateAlloc = FALSE;
// Determine surfaces to be used in the bitblt // Determine surfaces to be used in the bitblt
SurfDest = (PSURFOBJ)AccessUserObject(DCDest->Surface); SurfDest = (PSURFOBJ)AccessUserObject(DCDest->Surface);
@ -83,14 +84,16 @@ BOOL STDCALL W32kBitBlt(HDC hDCDest,
PalSourceGDI = (PPALGDI)AccessInternalObject(SourcePalette); PalSourceGDI = (PPALGDI)AccessInternalObject(SourcePalette);
XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestGDI->Mode, PalSourceGDI->Mode, DestPalette, SourcePalette); XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestGDI->Mode, PalSourceGDI->Mode, DestPalette, SourcePalette);
XlateAlloc = TRUE;
} }
// Perform the bitblt operation // Perform the bitblt operation
Status = IntEngBitBlt(SurfDest, SurfSrc, NULL, NULL, XlateObj, &DestRect, &SourcePoint, NULL, NULL, NULL, ROP); Status = IntEngBitBlt(SurfDest, SurfSrc, NULL, NULL, XlateObj, &DestRect, &SourcePoint, NULL, NULL, NULL, ROP);
if(SurfDestAlloc == TRUE) ExFreePool(SurfDest); if (XlateAlloc) EngDeleteXlate(XlateObj);
if(SurfSrcAlloc == TRUE) ExFreePool(SurfSrc); if (SurfDestAlloc) ExFreePool(SurfDest);
if (SurfSrcAlloc) ExFreePool(SurfSrc);
DC_ReleasePtr(hDCDest); DC_ReleasePtr(hDCDest);
DC_ReleasePtr(hDCSrc); DC_ReleasePtr(hDCSrc);

View file

@ -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 * DC.C - Device context functions
* *
@ -497,6 +497,7 @@ BOOL STDCALL W32kDeleteDC(HDC DCHandle)
BITMAPOBJ_ReleasePtr(DCToDelete->w.hBitmap); BITMAPOBJ_ReleasePtr(DCToDelete->w.hBitmap);
if (DCToDelete->w.flags & DC_MEMORY) if (DCToDelete->w.flags & DC_MEMORY)
{ {
EngDeleteSurface (DCToDelete->Surface);
W32kDeleteObject (DCToDelete->w.hFirstBitmap); W32kDeleteObject (DCToDelete->w.hFirstBitmap);
} }
} }
@ -1082,6 +1083,7 @@ HGDIOBJ STDCALL W32kSelectObject(HDC hDC, HGDIOBJ hGDIObj)
objOrg = (HGDIOBJ)dc->w.hBitmap; objOrg = (HGDIOBJ)dc->w.hBitmap;
/* Release the old bitmap, lock the new one and convert it to a SURF */ /* Release the old bitmap, lock the new one and convert it to a SURF */
EngDeleteSurface(dc->Surface);
BITMAPOBJ_ReleasePtr(objOrg); BITMAPOBJ_ReleasePtr(objOrg);
dc->w.hBitmap = hGDIObj; dc->w.hBitmap = hGDIObj;
pb = BITMAPOBJ_HandleToPtr(hGDIObj); pb = BITMAPOBJ_HandleToPtr(hGDIObj);

View file

@ -154,6 +154,8 @@ INT STDCALL W32kSetDIBits(HDC hDC,
} }
// Clean up // Clean up
EngDeleteXlate(XlateObj);
EngDeletePalette(DIB_Palette);
EngDeleteSurface(SourceBitmap); EngDeleteSurface(SourceBitmap);
EngDeleteSurface(DestBitmap); EngDeleteSurface(DestBitmap);