[glib/cherry-pick-e42aff25] Merge branch 'gio-appinfo-thread-crash' into 'master'




commit d4043d622ab5451935d90f56185cb35e1b150de4
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Mar 29 16:34:04 2021 +0000

    Merge branch 'gio-appinfo-thread-crash' into 'master'
    
    GIO W32: Pin gio DLL
    
    Closes #2300 and #2359
    
    See merge request GNOME/glib!2016
    
    (cherry picked from commit e42aff259223af6213ccb91b1453d2363f782a22)
    
    f701d6c4 GIO W32: Pin gio DLL
    03b574ae Don't leak a handle from _g_io_win32_get_module()

 gio/giomodule.c     | 3 ++-
 gio/gwin32appinfo.c | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/gio/giomodule.c b/gio/giomodule.c
index ca1daf2a8..a2909a8ef 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -1120,7 +1120,8 @@ void *
 _g_io_win32_get_module (void)
 {
   if (!gio_dll)
-    GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+    GetModuleHandleExA (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+                        GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                         (const char *) _g_io_win32_get_module,
                         &gio_dll);
   return gio_dll;
diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c
index b1709fbba..5403225e2 100644
--- a/gio/gwin32appinfo.c
+++ b/gio/gwin32appinfo.c
@@ -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);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]