http://bugs.winehq.org/show_bug.cgi?id=20711
--- Comment #25 from Markus mst@collogia.de 2010-03-30 09:22:40 ---
Doesn't that still try to call FreeLibrary() from apartment_release() -> COMPOBJ_DllList_ReleaseRef() though?
GetModuleHandleExW(0, ... increases the reference counter and ensures that the library is still loaded. So we can survive another call to FreeLibrary until DllCanUnloadNow is called. In this case we have to call FreeLibrary twice. One can be done in the original position.
Thanks to your comment I have seen another issue. COMPOBJ_DllList_ReleaseRef() releases the memory of entry. so I need a separate variable for that. Correction should be as follows:
static void apartment_freeunusedlibraries(struct apartment *apt, DWORD delay) { struct apartment_loaded_dll *entry, *next; * HANDLE hLibrary; * BOOL res;
...
* res = GetModuleHandleExW(0, entry->dll->library_name, &hLibrary); * if ( res && entry->dll->DllCanUnloadNow && (entry->dll->DllCanUnloadNow() == S_OK)) {
...
} else if (entry->unload_time) entry->unload_time = 0;
* if (res) FreeLibrary(hLibrary);