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

Alexandre Julliard julliard at winehq.org
Thu Feb 28 06:21:57 CST 2008


Module: wine
Branch: master
Commit: d284fd972f825f704a8bed77d7013e0a0e6bdcca
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d284fd972f825f704a8bed77d7013e0a0e6bdcca

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Thu Feb 28 11:21:52 2008 +0100

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

---

 dlls/mscms/handle.c  |    6 +++---
 dlls/mscms/profile.c |   32 ++++++++++++++++++++------------
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/dlls/mscms/handle.c b/dlls/mscms/handle.c
index fe474f3..09c2cc6 100644
--- a/dlls/mscms/handle.c
+++ b/dlls/mscms/handle.c
@@ -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
  *  color profile handle and a Windows file handle. Windows color profile 
  *  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'
- *  field records the access parameter supplied to an OpenColorProfile()
- *  call, i.e. PROFILE_READ or PROFILE_READWRITE.
+ *  the profile is memory based the file handle field is set to
+ *  INVALID_HANDLE_VALUE. The 'access' field records the access parameter
+ *  supplied to an OpenColorProfile() call, i.e. PROFILE_READ or PROFILE_READWRITE.
  */
 
 struct profile
diff --git a/dlls/mscms/profile.c b/dlls/mscms/profile.c
index 8f4931a..9122ecc 100644
--- a/dlls/mscms/profile.c
+++ b/dlls/mscms/profile.c
@@ -1370,14 +1370,14 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing
 #ifdef HAVE_LCMS
     cmsHPROFILE cmsprofile = NULL;
     icProfile *iccprofile = NULL;
-    HANDLE handle = NULL;
+    HANDLE handle = INVALID_HANDLE_VALUE;
     DWORD size;
 
     TRACE( "( %p, 0x%08x, 0x%08x, 0x%08x )\n", profile, access, sharing, creation );
 
     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 */
 
@@ -1386,8 +1386,7 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing
     
         cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
     }
-
-    if (profile->dwType & PROFILE_FILENAME)
+    else if (profile->dwType == PROFILE_FILENAME)
     {
         DWORD read, flags = 0;
 
@@ -1432,6 +1431,11 @@ HPROFILE WINAPI OpenColorProfileW( PPROFILE profile, DWORD access, DWORD sharing
 
         cmsprofile = cmsOpenProfileFromMem( iccprofile, size );
     }
+    else
+    {
+        ERR( "Invalid profile type %u\n", profile->dwType );
+        return NULL;
+    }
 
     if (cmsprofile)
         return MSCMS_create_hprofile_handle( handle, iccprofile, cmsprofile, access );
@@ -1462,19 +1466,23 @@ BOOL WINAPI CloseColorProfile( HPROFILE 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 ) ||
-            !WriteFile( file, iccprofile, size, &written, NULL ) || written != size)
-            ERR( "Unable to write color profile\n" );
+            if (SetFilePointer( file, 0, NULL, FILE_BEGIN ) ||
+                !WriteFile( file, iccprofile, size, &written, NULL ) || written != size)
+            {
+                ERR( "Unable to write color profile\n" );
+            }
+        }
+        CloseHandle( file );
     }
-
     ret = cmsCloseProfile( MSCMS_hprofile2cmsprofile( profile ) );
-    HeapFree( GetProcessHeap(), 0, MSCMS_hprofile2iccprofile( profile ) );
+    HeapFree( GetProcessHeap(), 0, iccprofile );
 
-    CloseHandle( MSCMS_hprofile2handle( profile ) );
     MSCMS_destroy_hprofile_handle( profile );
 
 #endif /* HAVE_LCMS */




More information about the wine-cvs mailing list