mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 20:33:22 +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);
|
IconDIR = MapViewOfFile(hSection, FILE_MAP_READ, 0, 0, 0);
|
||||||
CloseHandle(hSection);
|
CloseHandle(hSection);
|
||||||
if (IconDIR == NULL || 0 != IconDIR->idReserved
|
if (IconDIR == NULL)
|
||||||
|| (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
|
|
||||||
{
|
{
|
||||||
return 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
|
* Get a handle to the screen dc, the icon we create is going to be
|
||||||
* compatable with it.
|
* compatable with it.
|
||||||
|
@ -213,11 +219,17 @@ LoadCursorImage(HINSTANCE hinst, LPCWSTR lpszName, UINT fuLoad)
|
||||||
if (!dirEntry)
|
if (!dirEntry)
|
||||||
{
|
{
|
||||||
UnmapViewOfFile(IconDIR);
|
UnmapViewOfFile(IconDIR);
|
||||||
return(NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
|
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
|
||||||
|
if (SafeIconImage == NULL)
|
||||||
|
{
|
||||||
|
UnmapViewOfFile(IconDIR);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
|
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
|
||||||
|
UnmapViewOfFile(IconDIR);
|
||||||
|
|
||||||
/* at this point we have a copy of the icon image to play with */
|
/* at this point we have a copy of the icon image to play with */
|
||||||
|
|
||||||
|
@ -352,7 +364,7 @@ LoadIconImage(HINSTANCE hinst, LPCWSTR lpszName, INT width, INT height, UINT fuL
|
||||||
NULL);
|
NULL);
|
||||||
if (hFile == NULL)
|
if (hFile == NULL)
|
||||||
{
|
{
|
||||||
return(NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hSection = CreateFileMappingW(hFile,
|
hSection = CreateFileMappingW(hFile,
|
||||||
|
@ -362,43 +374,42 @@ LoadIconImage(HINSTANCE hinst, LPCWSTR lpszName, INT width, INT height, UINT fuL
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
CloseHandle(hFile);
|
||||||
if (hSection == NULL)
|
if (hSection == NULL)
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
return NULL;
|
||||||
return(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IconDIR = MapViewOfFile(hSection,
|
IconDIR = MapViewOfFile(hSection,
|
||||||
FILE_MAP_READ,
|
FILE_MAP_READ,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (IconDIR == NULL || 0 != IconDIR->idReserved
|
|
||||||
|| (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
|
|
||||||
{
|
|
||||||
CloseHandle(hFile);
|
|
||||||
CloseHandle(hSection);
|
CloseHandle(hSection);
|
||||||
return(NULL);
|
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.
|
//pick the best size.
|
||||||
dirEntry = (CURSORICONDIRENTRY *) CURSORICON_FindBestIcon( IconDIR, width, height, 1);
|
dirEntry = (CURSORICONDIRENTRY *) CURSORICON_FindBestIcon( IconDIR, width, height, 1);
|
||||||
|
|
||||||
|
|
||||||
if (!dirEntry)
|
if (!dirEntry)
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
|
||||||
CloseHandle(hSection);
|
|
||||||
UnmapViewOfFile(IconDIR);
|
UnmapViewOfFile(IconDIR);
|
||||||
return(NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
|
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
|
||||||
|
|
||||||
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
|
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
|
||||||
|
UnmapViewOfFile(IconDIR);
|
||||||
CloseHandle(hFile);
|
|
||||||
CloseHandle(hSection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//at this point we have a copy of the icon image to play with
|
//at this point we have a copy of the icon image to play with
|
||||||
|
@ -432,7 +443,6 @@ LoadIconImage(HINSTANCE hinst, LPCWSTR lpszName, INT width, INT height, UINT fuL
|
||||||
if (fuLoad & LR_LOADFROMFILE)
|
if (fuLoad & LR_LOADFROMFILE)
|
||||||
{
|
{
|
||||||
RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
|
RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
|
||||||
UnmapViewOfFile(IconDIR);
|
|
||||||
}
|
}
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
@ -684,6 +694,11 @@ CopyImage(HANDLE hnd, UINT type, INT desiredx, INT desiredy, UINT flags)
|
||||||
if ((res = CreateBitmapIndirect(&bm)))
|
if ((res = CreateBitmapIndirect(&bm)))
|
||||||
{
|
{
|
||||||
char *buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight);
|
char *buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight);
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
DeleteObject(res);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
GetBitmapBits(hnd, bm.bmWidthBytes * bm.bmHeight, buf);
|
GetBitmapBits(hnd, bm.bmWidthBytes * bm.bmHeight, buf);
|
||||||
SetBitmapBits(res, bm.bmWidthBytes * bm.bmHeight, buf);
|
SetBitmapBits(res, bm.bmWidthBytes * bm.bmHeight, buf);
|
||||||
HeapFree(GetProcessHeap(), 0, buf);
|
HeapFree(GetProcessHeap(), 0, buf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue