GIO W32: Pin gio DLL

On Windows gio runs a thread to update appinfo at startup.
If someone unloads gio (this happens when a dynamic gio module gets
unloaded by a program that doesn't use gio itself), there doesn't seem
to be a way to detect that until gio is already gone, and as soon as
gio is gone, the thread crashes, since it tries to execute instructions
that are no longer there.

Holding an extra reference to gio DLL fixes this, but it also prevents
gio from being unloaded, and there's no "weak references" for DLLs.
So we just pin gio and acknowledge that it will never be unloaded.

Fixes #2300
Fixes #2359
This commit is contained in:
Руслан Ижбулатов 2021-03-24 16:36:42 +00:00
parent 55cbc31517
commit f701d6c497

View File

@ -3964,6 +3964,8 @@ gio_win32_appinfo_init (gboolean do_wait)
if (g_once_init_enter (&initialized))
{
HMODULE gio_dll_extra;
url_associations_key =
g_win32_registry_key_new_w (L"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations",
NULL);
@ -4006,6 +4008,11 @@ gio_win32_appinfo_init (gboolean do_wait)
g_atomic_int_set (&gio_win32_appinfo_update_counter, 1);
/* Trigger initial tree build. Fake data pointer. */
g_thread_pool_push (gio_win32_appinfo_threadpool, (gpointer) keys_updated, NULL);
/* Increment the DLL refcount */
GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,
(const char *) gio_win32_appinfo_init,
&gio_dll_extra);
/* gio DLL cannot be unloaded now */
g_once_init_leave (&initialized, TRUE);
}