[OLE #21] Make apartment access thread safe, rework OLE TLS management (take 2)

Robert Shearman rob at codeweavers.com
Tue Jan 4 17:05:15 CST 2005

Mike Hearn wrote:

>On Tue, 04 Jan 2005 16:35:15 -0600, Robert Shearman wrote:
>>and obviously increment COM_CurrentInfo()->inits in CoInitializeEx. And 
>>we should only add a reference to the apartment once in CoInitializeEx.
>What does that buy us that a 1:1 mapping between CoInitializeEx and
>apartment refs doesn't? I'm not sure why refcounting the OLETLS structure
>is useful.

If you refcount the apartment then you could get the following situation:
Thread1: CoInitialize(MTA)
Thread2: CoInitialize(MTA) - note both threads now have a pointer to the 
same apt
Thread1: CoUninitialize() - still has pointer to MTA
Thread2: CoUninitialize() - detects apartment being destroyed and 
removes pointer to MTA
Thread1: Some marshalling function - BOOM! using free'd memory.

If you remove the pointer to the apartment on every CoUninitialize then 
you will break applications depending on it not separating from the 
apartment until the last CoUninitialize.


More information about the wine-devel mailing list