Commit d284fd97 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

mscms: Avoid closing a random file when destroying a memory based profile.

parent 54e6aa91
...@@ -44,9 +44,9 @@ static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0, ...@@ -44,9 +44,9 @@ static CRITICAL_SECTION MSCMS_handle_cs = { &MSCMS_handle_cs_debug, -1, 0, 0, 0,
/* A simple structure to tie together a pointer to an icc profile, an lcms /* A simple structure to tie together a pointer to an icc profile, an lcms
* color profile handle and a Windows file handle. Windows color profile * color profile handle and a Windows file handle. Windows color profile
* handles are built from indexes into an array of these structures. If * handles are built from indexes into an array of these structures. If
* the profile is memory based the file handle field is NULL. The 'access' * the profile is memory based the file handle field is set to
* field records the access parameter supplied to an OpenColorProfile() * INVALID_HANDLE_VALUE. The 'access' field records the access parameter
* call, i.e. PROFILE_READ or PROFILE_READWRITE. * supplied to an OpenColorProfile() call, i.e. PROFILE_READ or PROFILE_READWRITE.
*/ */
struct profile struct profile
......
...@@ -1370,14 +1370,14 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing ...@@ -1370,14 +1370,14 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing
#ifdef HAVE_LCMS #ifdef HAVE_LCMS
cmsHPROFILE cmsprofile = NULL; cmsHPROFILE cmsprofile = NULL;
icProfile *iccprofile = NULL; icProfile *iccprofile = NULL;
HANDLE handle = NULL; HANDLE handle = INVALID_HANDLE_VALUE;
DWORD size; DWORD size;
TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation ); TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
if (!profile || !profile->pProfileData) return NULL; if (!profile || !profile->pProfileData) return NULL;
if (profile->dwType & PROFILE_MEMBUFFER) if (profile->dwType == PROFILE_MEMBUFFER)
{ {
/* FIXME: access flags not implemented for memory based profiles */ /* FIXME: access flags not implemented for memory based profiles */
...@@ -1386,8 +1386,7 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing ...@@ -1386,8 +1386,7 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing
cmsprofile = cmsOpenProfileFromMem( iccprofile, size ); cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
} }
else if (profile->dwType == PROFILE_FILENAME)
if (profile->dwType & PROFILE_FILENAME)
{ {
DWORD read, flags = 0; DWORD read, flags = 0;
...@@ -1432,6 +1431,11 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing ...@@ -1432,6 +1431,11 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing
cmsprofile = cmsOpenProfileFromMem( iccprofile, size ); cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
} }
else
{
ERR( "Invalid profile type %u\n", profile->dwType );
return NULL;
}
if (cmsprofile) if (cmsprofile)
return MSCMS_create_hprofile_handle( handle, iccprofile, cmsprofile, access ); return MSCMS_create_hprofile_handle( handle, iccprofile, cmsprofile, access );
...@@ -1462,19 +1466,23 @@ BOOL WINAPI CloseColorProfile( HPROFILE profile ) ...@@ -1462,19 +1466,23 @@ BOOL WINAPI CloseColorProfile( HPROFILE profile )
TRACE( "( %p )\n", profile ); TRACE( "( %p )\n", profile );
if (file && (access & PROFILE_READWRITE)) if (file != INVALID_HANDLE_VALUE)
{ {
DWORD written, size = MSCMS_get_profile_size( iccprofile ); if (access & PROFILE_READWRITE)
{
DWORD written, size = MSCMS_get_profile_size( iccprofile );
if (SetFilePointer( file, 0, NULL, FILE_BEGIN ) || if (SetFilePointer( file, 0, NULL, FILE_BEGIN ) ||
!WriteFile( file, iccprofile, size, &written, NULL ) || written != size) !WriteFile( file, iccprofile, size, &written, NULL ) || written != size)
ERR( "Unable to write color profile\n" ); {
ERR( "Unable to write color profile\n" );
}
}
CloseHandle( file );
} }
ret = cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile ) ); ret = cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile ) );
HeapFree( GetProcessHeap(), 0, MSCMS_hprofile2iccprofile( profile ) ); HeapFree( GetProcessHeap(), 0, iccprofile );
CloseHandle( MSCMS_hprofile2handle( profile ) );
MSCMS_destroy_hprofile_handle( profile ); MSCMS_destroy_hprofile_handle( profile );
#endif /* HAVE_LCMS */ #endif /* HAVE_LCMS */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment