Commit 6af0e50f authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

ole32: Always grab a reference to apt in CoGetClassObject().

parent b0351a12
...@@ -1162,9 +1162,17 @@ DWORD apartment_release(struct apartment *apt) ...@@ -1162,9 +1162,17 @@ DWORD apartment_release(struct apartment *apt)
ret = InterlockedDecrement(&apt->refs); ret = InterlockedDecrement(&apt->refs);
TRACE("%s: after = %d\n", wine_dbgstr_longlong(apt->oxid), ret); TRACE("%s: after = %d\n", wine_dbgstr_longlong(apt->oxid), ret);
if (apt->being_destroyed)
{
LeaveCriticalSection(&csApartment);
return ret;
}
/* destruction stuff that needs to happen under csApartment CS */ /* destruction stuff that needs to happen under csApartment CS */
if (ret == 0) if (ret == 0)
{ {
apt->being_destroyed = TRUE;
if (apt == MTA) MTA = NULL; if (apt == MTA) MTA = NULL;
else if (apt == MainApartment) MainApartment = NULL; else if (apt == MainApartment) MainApartment = NULL;
list_remove(&apt->entry); list_remove(&apt->entry);
...@@ -2981,7 +2989,6 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -2981,7 +2989,6 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
IUnknown *regClassObject; IUnknown *regClassObject;
HRESULT hres = E_UNEXPECTED; HRESULT hres = E_UNEXPECTED;
APARTMENT *apt; APARTMENT *apt;
BOOL release_apt = FALSE;
TRACE("CLSID: %s,IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid)); TRACE("CLSID: %s,IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid));
...@@ -2990,14 +2997,15 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -2990,14 +2997,15 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
*ppv = NULL; *ppv = NULL;
if (!(apt = COM_CurrentApt())) if ((apt = COM_CurrentApt()))
apartment_addref(apt);
else
{ {
if (!(apt = apartment_find_mta())) if (!(apt = apartment_find_mta()))
{ {
ERR("apartment not initialised\n"); ERR("apartment not initialised\n");
return CO_E_NOTINITIALIZED; return CO_E_NOTINITIALIZED;
} }
release_apt = TRUE;
} }
if (pServerInfo) { if (pServerInfo) {
...@@ -3009,7 +3017,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -3009,7 +3017,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
{ {
if (IsEqualCLSID(rclsid, &CLSID_InProcFreeMarshaler)) if (IsEqualCLSID(rclsid, &CLSID_InProcFreeMarshaler))
{ {
if (release_apt) apartment_release(apt); apartment_release(apt);
return FTMarshalCF_Create(iid, ppv); return FTMarshalCF_Create(iid, ppv);
} }
if (IsEqualCLSID(rclsid, &CLSID_GlobalOptions)) if (IsEqualCLSID(rclsid, &CLSID_GlobalOptions))
...@@ -3035,7 +3043,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -3035,7 +3043,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
hres = get_inproc_class_object(apt, &clsreg, &comclass->clsid, iid, !(dwClsContext & WINE_CLSCTX_DONT_HOST), ppv); hres = get_inproc_class_object(apt, &clsreg, &comclass->clsid, iid, !(dwClsContext & WINE_CLSCTX_DONT_HOST), ppv);
ReleaseActCtx(data.hActCtx); ReleaseActCtx(data.hActCtx);
if (release_apt) apartment_release(apt); apartment_release(apt);
return hres; return hres;
} }
} }
...@@ -3056,7 +3064,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -3056,7 +3064,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
* is good since we are not returning it in the "out" parameter. * is good since we are not returning it in the "out" parameter.
*/ */
IUnknown_Release(regClassObject); IUnknown_Release(regClassObject);
if (release_apt) apartment_release(apt); apartment_release(apt);
return hres; return hres;
} }
...@@ -3091,7 +3099,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -3091,7 +3099,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
* other types */ * other types */
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
{ {
if (release_apt) apartment_release(apt); apartment_release(apt);
return hres; return hres;
} }
} }
...@@ -3127,11 +3135,11 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject( ...@@ -3127,11 +3135,11 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
* other types */ * other types */
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
{ {
if (release_apt) apartment_release(apt); apartment_release(apt);
return hres; return hres;
} }
} }
if (release_apt) apartment_release(apt); apartment_release(apt);
/* Next try out of process */ /* Next try out of process */
if (CLSCTX_LOCAL_SERVER & dwClsContext) if (CLSCTX_LOCAL_SERVER & dwClsContext)
......
...@@ -142,6 +142,7 @@ struct apartment ...@@ -142,6 +142,7 @@ struct apartment
DWORD host_apt_tid; /* thread ID of apartment hosting objects of differing threading model (CS cs) */ DWORD host_apt_tid; /* thread ID of apartment hosting objects of differing threading model (CS cs) */
HWND host_apt_hwnd; /* handle to apartment window of host apartment (CS cs) */ HWND host_apt_hwnd; /* handle to apartment window of host apartment (CS cs) */
LocalServer *local_server; /* A marshallable object exposing local servers (CS cs) */ LocalServer *local_server; /* A marshallable object exposing local servers (CS cs) */
BOOL being_destroyed; /* is currently being destroyed */
/* FIXME: OIDs should be given out by RPCSS */ /* FIXME: OIDs should be given out by RPCSS */
OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */ OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
......
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