Mike Hearn wrote:
On Tue, 2005-01-04 at 15:27 -0600, Robert Shearman wrote:
Because inits should be thread-local, not apartment scoped. NtCurrentTeb()->ReservedForOle should be set to NULL when the matching CoUninitialize is called, not when the apartment is destroyed.
I was under the impression that CoSetState/*ErrorInfo weren't tied to apartments at all, hence the whole uninitialised apartments thing. So it's not right to set ReservedForOle to NULL when CoUninitialise is called with this patch because ReservedForOle now points to a struct oletls not an apartment (which should be refcounted so CoUninitialise in the MTA doesn't trigger its destruction).
You are right. My tests show that the TLS state struct isn't be freed when the final CoUninitialize is called. However, it should still detach from the apartment. I believe we should do something like this in CoUninitialize:
if (!--COM_CurrentInfo()->inits) { COM_ApartmentRelease(COM_CurrentInfo()->apt); COM_CurrentInfo()->apt = NULL; }
and obviously increment COM_CurrentInfo()->inits in CoInitializeEx. And we should only add a reference to the apartment once in CoInitializeEx.
That does leave the question of how to free the OLE TLS data though. Presumably in a THREAD_DETACH notification.
That sounds like the best plan, otherwise we will leak a small amount of memory for each thread that uses COM functions.
Rob