Henning Hoffmann

Avoid deadlocks in EnumMetaFile.
This commit is contained in:
Alexandre Julliard 2000-09-19 02:37:48 +00:00
parent 9005713d39
commit ab86a9e563
1 changed files with 27 additions and 8 deletions

View File

@ -658,10 +658,10 @@ BOOL WINAPI EnumMetaFile(
MFENUMPROC lpEnumFunc,
LPARAM lpData
) {
METAHEADER *mh = MF_GetMetaHeader(hmf);
METAHEADER *mhTemp = NULL, *mh = MF_GetMetaHeader(hmf);
METARECORD *mr;
HANDLETABLE *ht;
BOOL result = TRUE, loaded = FALSE;
BOOL result = TRUE;
int i, offset = 0;
HPEN hPen;
HBRUSH hBrush;
@ -671,10 +671,30 @@ BOOL WINAPI EnumMetaFile(
hdc, hmf, lpEnumFunc, (void*)lpData);
if (!mh) return 0;
if(mh->mtType == METAFILE_DISK) { /* Create a memory-based copy */
mh = MF_LoadDiskBasedMetaFile(mh);
if(!mh) return 0;
loaded = TRUE;
mhTemp = MF_LoadDiskBasedMetaFile(mh);
if(!mhTemp)
{
MF_ReleaseMetaHeader(hmf);
return FALSE;
}
mh = mhTemp;
}
else
{
/* We need to copy this thing instead of use it directly because we
* have to close the hmf handle for the purpose of avoiding deadlock.
*/
mhTemp = HeapAlloc( GetProcessHeap(), 0, mh->mtHeaderSize + mh->mtSize*2 );
if(!mhTemp)
{
MF_ReleaseMetaHeader(hmf);
return FALSE;
}
memcpy( mhTemp, mh, mh->mtHeaderSize + mh->mtSize*2 );
mh = mhTemp;
}
MF_ReleaseMetaHeader(hmf);
hmf = 0; /* just in case */
/* save the current pen, brush and font */
hPen = GetCurrentObject(hdc, OBJ_PEN);
@ -713,9 +733,8 @@ BOOL WINAPI EnumMetaFile(
/* free handle table */
HeapFree( GetProcessHeap(), 0, ht);
if(loaded)
/* free a copy of metafile */
HeapFree( GetProcessHeap(), 0, mh );
MF_ReleaseMetaHeader(hmf);
return result;
}