Fix a possible memory leak when extracting from an ICO file.
Fix some signed/unsigned warnings showing up in MSVC with default warning level. Fix possible problem with short PIMAGE_NT_HEADERS.
This commit is contained in:
parent
ea1ca9c705
commit
117d5326fd
|
@ -254,7 +254,7 @@ static UINT ICO_ExtractIconExW(
|
|||
UINT *pIconId,
|
||||
UINT flags)
|
||||
{
|
||||
UINT ret = 0xFFFFFFFF;
|
||||
UINT ret = 0;
|
||||
UINT cx1, cx2, cy1, cy2;
|
||||
LPBYTE pData;
|
||||
DWORD sig;
|
||||
|
@ -277,20 +277,17 @@ static UINT ICO_ExtractIconExW(
|
|||
if (!fmapping)
|
||||
{
|
||||
WARN("CreateFileMapping error %ld\n", GetLastError() );
|
||||
return ret;
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
if (!(peimage = MapViewOfFile(fmapping, FILE_MAP_READ, 0, 0, 0)))
|
||||
{
|
||||
WARN("MapViewOfFile error %ld\n", GetLastError() );
|
||||
CloseHandle(fmapping);
|
||||
return ret;
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
CloseHandle(fmapping);
|
||||
|
||||
/* Initialize return value to 0 to indicate extraction error */
|
||||
ret = 0;
|
||||
|
||||
cx1 = LOWORD(cxDesired);
|
||||
cx2 = HIWORD(cxDesired) ? HIWORD(cxDesired) : cx1;
|
||||
cy1 = LOWORD(cyDesired);
|
||||
|
@ -304,7 +301,7 @@ static UINT ICO_ExtractIconExW(
|
|||
|
||||
sig = USER32_GetResourceTable(peimage, fsizel, &pData);
|
||||
|
||||
/* ico file */
|
||||
/* ico file or NE exe/dll*/
|
||||
if (sig==IMAGE_OS2_SIGNATURE || sig==1) /* .ICO file */
|
||||
{
|
||||
BYTE *pCIDir = 0;
|
||||
|
@ -317,7 +314,6 @@ static UINT ICO_ExtractIconExW(
|
|||
|
||||
if (pData == (BYTE*)-1)
|
||||
{
|
||||
/* FIXME: pCIDir is allocated on the heap - memory leak */
|
||||
pCIDir = ICO_GetIconDirectory(peimage, &lpiID, &uSize); /* check for .ICO file */
|
||||
if (pCIDir)
|
||||
{
|
||||
|
@ -347,6 +343,8 @@ static UINT ICO_ExtractIconExW(
|
|||
if (nIcons == 0)
|
||||
{
|
||||
ret = iconDirCount;
|
||||
if (lpiID && pCIDir) /* *.ico file, deallocate heap pointer*/
|
||||
HeapFree(GetProcessHeap(), 0, pCIDir);
|
||||
}
|
||||
else if (nIconIndex < iconDirCount)
|
||||
{
|
||||
|
@ -357,10 +355,12 @@ static UINT ICO_ExtractIconExW(
|
|||
for (i = 0; i < nIcons; i++)
|
||||
{
|
||||
/* .ICO files have only one icon directory */
|
||||
if( lpiID == NULL ) /* *.ico */
|
||||
if (lpiID == NULL) /* not *.ico */
|
||||
pCIDir = USER32_LoadResource(peimage, pIconDir + i + nIconIndex, *(WORD*)pData, &uSize);
|
||||
pIconId[i] = LookupIconIdFromDirectoryEx(pCIDir, TRUE, (i & 1) ? cx2 : cx1, (i & 1) ? cy2 : cy1, flags);
|
||||
}
|
||||
if (lpiID && pCIDir) /* *.ico file, deallocate heap pointer*/
|
||||
HeapFree(GetProcessHeap(), 0, pCIDir);
|
||||
|
||||
for (icon = 0; icon < nIcons; icon++)
|
||||
{
|
||||
|
@ -394,11 +394,12 @@ static UINT ICO_ExtractIconExW(
|
|||
const IMAGE_RESOURCE_DIRECTORY *rootresdir,*iconresdir,*icongroupresdir;
|
||||
const IMAGE_RESOURCE_DATA_ENTRY *idataent,*igdataent;
|
||||
const IMAGE_RESOURCE_DIRECTORY_ENTRY *xresent;
|
||||
int i,j;
|
||||
UINT i, j;
|
||||
|
||||
dheader = (PIMAGE_DOS_HEADER)peimage;
|
||||
pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); /* it is a pe header, USER32_GetResourceTable checked that */
|
||||
pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); /* probably makes problems with short PE headers...*/
|
||||
pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER)
|
||||
+ pe_header->FileHeader.SizeOfOptionalHeader);
|
||||
rootresdir = NULL;
|
||||
|
||||
/* search for the root resource directory */
|
||||
|
|
Loading…
Reference in New Issue