Handle some out of resource situations

svn path=/trunk/; revision=6145
This commit is contained in:
Gé van Geldorp 2003-09-26 10:45:45 +00:00
parent 5a99fbb2ce
commit b13d959501
5 changed files with 75 additions and 29 deletions

View file

@ -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: mem.c,v 1.11 2003/07/11 15:59:37 royce Exp $
/* $Id: mem.c,v 1.12 2003/09/26 10:45:44 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -53,7 +53,7 @@ EngAllocMem(ULONG Flags,
newMem = ExAllocatePoolWithTag(NonPagedPool, MemSize, Tag); // FIXME: Use PagedPool when it is implemented
if(Flags == FL_ZERO_MEMORY)
if (Flags == FL_ZERO_MEMORY && NULL != newMem)
{
RtlZeroMemory(newMem, MemSize);
}

View file

@ -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: xlate.c,v 1.24 2003/08/31 07:56:24 gvg Exp $
/* $Id: xlate.c,v 1.25 2003/09/26 10:45:44 gvg Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -202,6 +202,28 @@ static INT FASTCALL CalculateShift(ULONG Mask)
return Shift;
}
VOID FASTCALL EngDeleteXlate(XLATEOBJ *XlateObj)
{
XLATEGDI *XlateGDI;
HANDLE HXlate;
if (NULL == XlateObj)
{
DPRINT1("Trying to delete NULL XLATEOBJ\n");
return;
}
XlateGDI = (XLATEGDI *) AccessInternalObjectFromUserObject(XlateObj);
HXlate = (HANDLE) AccessHandleFromUserObject(XlateObj);
if(NULL != XlateGDI->translationTable)
{
EngFreeMem(XlateGDI->translationTable);
}
FreeGDIHandle((ULONG)HXlate);
}
XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
HPALETTE PaletteDest, HPALETTE PaletteSource)
{
@ -319,6 +341,19 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
else if (DestPalType == PAL_INDEXED) { IndexedColors = DestPalGDI->NumColors; }
XlateGDI->translationTable = EngAllocMem(FL_ZERO_MEMORY, sizeof(ULONG)*IndexedColors, 0);
if (NULL == XlateGDI->translationTable)
{
if (NULL != PaletteSource)
{
PALETTE_UnlockPalette(PaletteSource);
}
if (NULL != PaletteDest && PaletteDest != PaletteSource)
{
PALETTE_UnlockPalette(PaletteDest);
}
EngDeleteXlate(XlateObj);
return NULL;
}
}
// Source palette is indexed
@ -375,19 +410,6 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
return XlateObj;
}
VOID FASTCALL EngDeleteXlate(XLATEOBJ *XlateObj)
{
HANDLE HXlate = (HANDLE)AccessHandleFromUserObject(XlateObj);
XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObject((ULONG)HXlate);
if(XlateGDI->translationTable!=NULL)
{
EngFreeMem(XlateGDI->translationTable);
}
FreeGDIHandle((ULONG)HXlate);
}
/*
* @implemented
*/

View file

@ -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: dc.c,v 1.81 2003/09/21 06:44:51 gvg Exp $
/* $Id: dc.c,v 1.82 2003/09/26 10:45:45 gvg Exp $
*
* DC.C - Device context functions
*
@ -42,6 +42,7 @@
#include <win32k/text.h>
#include "../eng/clip.h"
#include "../eng/handle.h"
#include <include/error.h>
#include <include/inteng.h>
#include <include/eng.h>
#include <include/palette.h>
@ -1486,13 +1487,17 @@ NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj)
case GDI_OBJECT_TYPE_BITMAP:
// must be memory dc to select bitmap
if (!(dc->w.flags & DC_MEMORY)) return NULL;
pb = BITMAPOBJ_LockBitmap(hGDIObj);
if (NULL == pb)
{
SetLastWin32Error(ERROR_INVALID_HANDLE);
return NULL;
}
objOrg = (HGDIOBJ)dc->w.hBitmap;
/* Release the old bitmap, lock the new one and convert it to a SURF */
EngDeleteSurface(dc->Surface);
dc->w.hBitmap = hGDIObj;
pb = BITMAPOBJ_LockBitmap(hGDIObj);
ASSERT(pb);
dc->Surface = BitmapToSurf(pb);
// if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]

View file

@ -1,5 +1,5 @@
/*
* $Id: dib.c,v 1.33 2003/09/25 14:40:42 fireball Exp $
* $Id: dib.c,v 1.34 2003/09/26 10:45:45 gvg Exp $
*
* ReactOS W32 Subsystem
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
@ -164,9 +164,28 @@ NtGdiSetDIBits(
// Source palette obtained from the BITMAPINFO
DIB_Palette = BuildDIBPalette ( (PBITMAPINFO)bmi, (PINT)&DIB_Palette_Type );
if (NULL == DIB_Palette)
{
EngDeleteSurface(SourceBitmap);
EngDeleteSurface(DestBitmap);
BITMAPOBJ_UnlockBitmap(hBitmap);
DC_UnlockDc(hDC);
SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
return 0;
}
// Determine XLATEOBJ for color translation
XlateObj = IntEngCreateXlate(DDB_Palette_Type, DIB_Palette_Type, DDB_Palette, DIB_Palette);
if (NULL == XlateObj)
{
PALETTE_FreePalette(DIB_Palette);
EngDeleteSurface(SourceBitmap);
EngDeleteSurface(DestBitmap);
BITMAPOBJ_UnlockBitmap(hBitmap);
DC_UnlockDc(hDC);
SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
return 0;
}
// Zero point
ZeroPoint.x = 0;

View file

@ -19,7 +19,7 @@
/*
* GDIOBJ.C - GDI object manipulation routines
*
* $Id: gdiobj.c,v 1.43 2003/09/24 16:01:32 weiden Exp $
* $Id: gdiobj.c,v 1.44 2003/09/26 10:45:45 gvg Exp $
*
*/
@ -41,9 +41,15 @@
#define NDEBUG
#include <win32k/debug1.h>
/*! Size of the GDI handle table
* http://www.windevnet.com/documents/s=7290/wdj9902b/9902b.htm
* gdi handle table can hold 0x4000 handles
*/
#define GDI_HANDLE_COUNT 0x4000
#define GDI_GLOBAL_PROCESS ((HANDLE) 0xffffffff)
#define GDI_HANDLE_INDEX_MASK 0x00003fff
#define GDI_HANDLE_INDEX_MASK (GDI_HANDLE_COUNT - 1)
#define GDI_HANDLE_TYPE_MASK 0x007f0000
#define GDI_HANDLE_STOCK_MASK 0x00800000
@ -140,12 +146,6 @@ static PGDI_HANDLE_TABLE HandleTable = 0;
static FAST_MUTEX HandleTableMutex;
static FAST_MUTEX RefCountHandling;
/*! Size of the GDI handle table
* http://www.windevnet.com/documents/s=7290/wdj9902b/9902b.htm
* gdi handle table can hold 0x4000 handles
*/
#define GDI_HANDLE_NUMBER 0x4000
/*!
* Allocate GDI object table.
* \param Size - number of entries in the object table.
@ -471,7 +471,7 @@ InitGdiObjectHandleTable (VOID)
ExInitializeFastMutex (&HandleTableMutex);
ExInitializeFastMutex (&RefCountHandling);
HandleTable = GDIOBJ_iAllocHandleTable (GDI_HANDLE_NUMBER);
HandleTable = GDIOBJ_iAllocHandleTable (GDI_HANDLE_COUNT);
DPRINT("HandleTable: %x\n", HandleTable );
InitEngHandleTable();