ole32: Fix hosting in main apartments.

Robert Shearman rob at codeweavers.com
Sat May 19 11:21:00 CDT 2007


The recently introduced code had a bug where it passed the wrong values 
into apartment_findfromtype to find the main apartment. Since this is 
now the only way the function is used, fix this bug by changing 
apartment_findfromtype to apartment_findmain, which only finds the main 
apartment.
---
  dlls/ole32/compobj.c |   29 +++++++----------------------
  1 files changed, 7 insertions(+), 22 deletions(-)
-------------- next part --------------
diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c
index 8e883a8..d9404a1 100644
--- a/dlls/ole32/compobj.c
+++ b/dlls/ole32/compobj.c
@@ -474,33 +474,18 @@ APARTMENT *apartment_findfromtid(DWORD t
     return result;
 }
 
-/* gets an apartment which has a given type. The caller must
+/* gets the main apartment if it exists. The caller must
  * release the reference from the apartment as soon as the apartment pointer
  * is no longer required. */
-static APARTMENT *apartment_findfromtype(BOOL multi_threaded, BOOL main_apartment)
+static APARTMENT *apartment_findmain(void)
 {
-    APARTMENT *result = NULL;
-    struct apartment *apt;
+    APARTMENT *result;
 
     EnterCriticalSection(&csApartment);
 
-    if (!multi_threaded && main_apartment)
-    {
-        result = MainApartment;
-        if (result) apartment_addref(result);
-        LeaveCriticalSection(&csApartment);
-        return result;
-    }
+    result = MainApartment;
+    if (result) apartment_addref(result);
 
-    LIST_FOR_EACH_ENTRY( apt, &apts, struct apartment, entry )
-    {
-        if (apt->multi_threaded == multi_threaded)
-        {
-            result = apt;
-            apartment_addref(result);
-            break;
-        }
-    }
     LeaveCriticalSection(&csApartment);
 
     return result;
@@ -624,7 +609,7 @@ static HRESULT apartment_hostobject_in_h
 
     if (!multi_threaded && main_apartment)
     {
-        APARTMENT *host_apt = apartment_findfromtype(FALSE, FALSE);
+        APARTMENT *host_apt = apartment_findmain();
         if (host_apt)
         {
             apartment_hwnd = apartment_getwindow(host_apt);
@@ -677,7 +662,7 @@ static HRESULT apartment_hostobject_in_h
      * us to create the thread for the host apartment */
     if (!apartment_hwnd && !multi_threaded && main_apartment)
     {
-        APARTMENT *host_apt = apartment_findfromtype(FALSE, FALSE);
+        APARTMENT *host_apt = apartment_findmain();
         if (host_apt)
         {
             apartment_hwnd = apartment_getwindow(host_apt);


More information about the wine-patches mailing list