Author: tkreuzer Date: Wed May 2 13:56:55 2012 New Revision: 56476
URL: http://svn.reactos.org/svn/reactos?rev=56476&view=rev Log: [WIN32K] - Fix a palette leak in DIB_CreateDIBSection - Remove PALETTE_AllocPalette and PALETTE_AllocPaletteIndexedRGB, use PALETTE_AllocPalWithHandle instead
Modified: trunk/reactos/win32ss/gdi/ntgdi/dibobj.c trunk/reactos/win32ss/gdi/ntgdi/palette.c trunk/reactos/win32ss/gdi/ntgdi/palette.h
Modified: trunk/reactos/win32ss/gdi/ntgdi/dibobj.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/dibobj.c?... ============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/dibobj.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/dibobj.c [iso-8859-1] Wed May 2 13:56:55 2012 @@ -1599,7 +1599,14 @@ /* HACK */ if(hpal != (HPALETTE)0xFFFFFFFF) { - bmp->ppal = PALETTE_ShareLockPalette(hpal); + PPALETTE ppal = PALETTE_ShareLockPalette(hpal); + + if (ppal) + { + if (bmp->ppal) PALETTE_ShareUnlockPalette(bmp->ppal); + bmp->ppal = ppal; + } + /* Lazy delete hpal, it will be freed at surface release */ GreDeleteObject(hpal); } @@ -1771,10 +1778,11 @@ { WORD bits; ULONG ColorCount; - HPALETTE hPal; + HPALETTE hpal; + PPALETTE ppal; ULONG RedMask = 0, GreenMask = 0, BlueMask = 0; PDWORD pdwColors = (PDWORD)((PBYTE)bmi + bmi->bmiHeader.biSize); - INT paletteType; + ULONG paletteType, i;
// Determine Bits Per Pixel bits = bmi->bmiHeader.biBitCount; @@ -1833,18 +1841,41 @@ ColorCount = bmi->bmiHeader.biClrUsed; }
- if (PAL_INDEXED == paletteType) - { - hPal = PALETTE_AllocPaletteIndexedRGB(ColorCount, (RGBQUAD*)pdwColors); + if (paletteType == PAL_INDEXED) + { + RGBQUAD* pColors = (RGBQUAD*)((PBYTE)bmi + bmi->bmiHeader.biSize); + + /* Allocate a palette */ + ppal = PALETTE_AllocPalWithHandle(PAL_INDEXED, + ColorCount, + NULL, + 0, 0, 0); + if (!ppal) return NULL; + + /* Copy all colors */ + for (i = 0; i < ColorCount; i++) + { + ppal->IndexedColors[i].peRed = pColors[i].rgbRed; + ppal->IndexedColors[i].peGreen = pColors[i].rgbGreen; + ppal->IndexedColors[i].peBlue = pColors[i].rgbBlue; + ppal->IndexedColors[i].peFlags = 0; + } + + /* Get palette handle and unlock the palette */ + hpal = ppal->BaseObject.hHmgr; + PALETTE_UnlockPalette(ppal); } else { - hPal = PALETTE_AllocPalette(paletteType, 0, - NULL, - RedMask, GreenMask, BlueMask); - } - - return hPal; + ppal = PALETTE_AllocPalWithHandle(paletteType, 0, + NULL, + RedMask, GreenMask, BlueMask); + + hpal = ppal->BaseObject.hHmgr; + PALETTE_UnlockPalette(ppal); + } + + return hpal; }
/* Converts a BITMAPCOREINFO to a BITMAPINFO structure,
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.c... ============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] Wed May 2 13:56:55 2012 @@ -228,87 +228,6 @@ }
return ppal; -} - -HPALETTE -FASTCALL -PALETTE_AllocPalette(ULONG Mode, - ULONG NumColors, - ULONG *Colors, - ULONG Red, - ULONG Green, - ULONG Blue) -{ - PPALETTE ppal; - HPALETTE hpal; - - ppal = PALETTE_AllocPalette2(Mode, NumColors, Colors, Red, Green, Blue); - if (!ppal) return NULL; - - hpal = GDIOBJ_hInsertObject(&ppal->BaseObject, GDI_OBJ_HMGR_POWNED); - if (!hpal) - { - DPRINT1("Could not insert palette into handle table.\n"); - GDIOBJ_vFreeObject(&ppal->BaseObject); - return NULL; - } - - PALETTE_UnlockPalette(ppal); - - return hpal; -} - -HPALETTE -FASTCALL -PALETTE_AllocPaletteIndexedRGB(ULONG NumColors, - CONST RGBQUAD *Colors) -{ - HPALETTE NewPalette; - PPALETTE PalGDI; - UINT i; - - PalGDI = (PPALETTE)GDIOBJ_AllocateObject(GDIObjType_PAL_TYPE, - sizeof(PALETTE), - BASEFLAG_LOOKASIDE); - if (!PalGDI) - { - DPRINT1("Could not allocate a palette.\n"); - return NULL; - } - - if (!GDIOBJ_hInsertObject(&PalGDI->BaseObject, GDI_OBJ_HMGR_POWNED)) - { - DPRINT1("Could not insert palette into handle table.\n"); - GDIOBJ_vFreeObject(&PalGDI->BaseObject); - return NULL; - } - - NewPalette = PalGDI->BaseObject.hHmgr; - - PalGDI->flFlags = PAL_INDEXED; - - PalGDI->IndexedColors = ExAllocatePoolWithTag(PagedPool, - sizeof(PALETTEENTRY) * NumColors, - TAG_PALETTE); - if (NULL == PalGDI->IndexedColors) - { - GDIOBJ_vDeleteObject(&PalGDI->BaseObject); - return NULL; - } - - for (i = 0; i < NumColors; i++) - { - PalGDI->IndexedColors[i].peRed = Colors[i].rgbRed; - PalGDI->IndexedColors[i].peGreen = Colors[i].rgbGreen; - PalGDI->IndexedColors[i].peBlue = Colors[i].rgbBlue; - PalGDI->IndexedColors[i].peFlags = 0; - } - - PalGDI->NumColors = NumColors; - - PALETTE_UnlockPalette(PalGDI); - - return NewPalette; }
BOOL
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.h... ============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] Wed May 2 13:56:55 2012 @@ -156,9 +156,3 @@ ULONG Red, ULONG Green, ULONG Blue); - -HPALETTE -FASTCALL -PALETTE_AllocPaletteIndexedRGB(ULONG NumColors, - CONST RGBQUAD *Colors); -