mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 17:25:55 +00:00
Check for failed allocations and fix some resource leaks.
svn path=/trunk/; revision=20117
This commit is contained in:
parent
4612bb691c
commit
f59f8f34e3
1 changed files with 48 additions and 33 deletions
|
@ -176,12 +176,18 @@ LoadCursorImage(HINSTANCE hinst, LPCWSTR lpszName, UINT fuLoad)
|
|||
|
||||
IconDIR = MapViewOfFile(hSection, FILE_MAP_READ, 0, 0, 0);
|
||||
CloseHandle(hSection);
|
||||
if (IconDIR == NULL || 0 != IconDIR->idReserved
|
||||
|| (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
|
||||
if (IconDIR == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (0 != IconDIR->idReserved ||
|
||||
(IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
|
||||
{
|
||||
UnmapViewOfFile(IconDIR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a handle to the screen dc, the icon we create is going to be
|
||||
* compatable with it.
|
||||
|
@ -213,11 +219,17 @@ LoadCursorImage(HINSTANCE hinst, LPCWSTR lpszName, UINT fuLoad)
|
|||
if (!dirEntry)
|
||||
{
|
||||
UnmapViewOfFile(IconDIR);
|
||||
return(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
|
||||
if (SafeIconImage == NULL)
|
||||
{
|
||||
UnmapViewOfFile(IconDIR);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
|
||||
UnmapViewOfFile(IconDIR);
|
||||
|
||||
/* at this point we have a copy of the icon image to play with */
|
||||
|
||||
|
@ -351,9 +363,9 @@ LoadIconImage(HINSTANCE hinst, LPCWSTR lpszName, INT width, INT height, UINT fuL
|
|||
0,
|
||||
NULL);
|
||||
if (hFile == NULL)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hSection = CreateFileMappingW(hFile,
|
||||
NULL,
|
||||
|
@ -362,43 +374,42 @@ LoadIconImage(HINSTANCE hinst, LPCWSTR lpszName, INT width, INT height, UINT fuL
|
|||
0,
|
||||
NULL);
|
||||
|
||||
CloseHandle(hFile);
|
||||
if (hSection == NULL)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
return(NULL);
|
||||
}
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IconDIR = MapViewOfFile(hSection,
|
||||
FILE_MAP_READ,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
|
||||
if (IconDIR == NULL || 0 != IconDIR->idReserved
|
||||
|| (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
CloseHandle(hSection);
|
||||
return(NULL);
|
||||
}
|
||||
CloseHandle(hSection);
|
||||
if (IconDIR == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (0 != IconDIR->idReserved ||
|
||||
(IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
|
||||
{
|
||||
UnmapViewOfFile(IconDIR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//pick the best size.
|
||||
dirEntry = (CURSORICONDIRENTRY *) CURSORICON_FindBestIcon( IconDIR, width, height, 1);
|
||||
|
||||
|
||||
if (!dirEntry)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
CloseHandle(hSection);
|
||||
UnmapViewOfFile(IconDIR);
|
||||
return(NULL);
|
||||
}
|
||||
{
|
||||
UnmapViewOfFile(IconDIR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
|
||||
|
||||
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
|
||||
|
||||
CloseHandle(hFile);
|
||||
CloseHandle(hSection);
|
||||
UnmapViewOfFile(IconDIR);
|
||||
}
|
||||
|
||||
//at this point we have a copy of the icon image to play with
|
||||
|
@ -430,10 +441,9 @@ LoadIconImage(HINSTANCE hinst, LPCWSTR lpszName, INT width, INT height, UINT fuL
|
|||
if (hScreenDc == NULL)
|
||||
{
|
||||
if (fuLoad & LR_LOADFROMFILE)
|
||||
{
|
||||
RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
|
||||
UnmapViewOfFile(IconDIR);
|
||||
}
|
||||
{
|
||||
RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
@ -684,6 +694,11 @@ CopyImage(HANDLE hnd, UINT type, INT desiredx, INT desiredy, UINT flags)
|
|||
if ((res = CreateBitmapIndirect(&bm)))
|
||||
{
|
||||
char *buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight);
|
||||
if (buf == NULL)
|
||||
{
|
||||
DeleteObject(res);
|
||||
return NULL;
|
||||
}
|
||||
GetBitmapBits(hnd, bm.bmWidthBytes * bm.bmHeight, buf);
|
||||
SetBitmapBits(res, bm.bmWidthBytes * bm.bmHeight, buf);
|
||||
HeapFree(GetProcessHeap(), 0, buf);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue