[gnome-software: 1/3] gs-plugin: Make plugins resident so they can’t be unloaded




commit b719c1aab54d65c422fda3df53e18146c1f3cd75
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Jun 17 16:11:28 2022 +0100

    gs-plugin: Make plugins resident so they can’t be unloaded
    
    Otherwise the unit tests fail when reloading the plugins for the first
    time, as the static type variable in (for example)
    `gs_plugin_flatpak_get_type()` is re-initialised to zero, causing the
    `GsPluginFlatpak` type to be re-registered with GObject — but GObject
    rejects that as `GsPluginFlatpak` has already been registered.
    
    This should fix the unit tests, and shouldn’t affect the behaviour of
    the normal application, because plugins are never unloaded by it except
    at shutdown time. (Even plugins which fail setup are disabled but not
    unloaded.)
    
    This bug is only visible when compiling with valgrind support disabled:
    when valgrind support is enabled, `g_module_close()` is never called on
    a `GsPlugin`, which has a similar effect.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    https://phabricator.endlessm.com/T33424

 lib/gs-plugin.c | 6 ++++++
 1 file changed, 6 insertions(+)
---
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 6e87814ae..e1af1c450 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -207,6 +207,12 @@ gs_plugin_create (const gchar      *filename,
                return NULL;
        }
 
+       /* Make the module resident so it can’t be unloaded: without using a
+        * full #GTypePlugin implementation for the modules, it’s not safe to
+        * re-load a module and re-register its types with GObject, as that will
+        * confuse the GType system. */
+       g_module_make_resident (module);
+
        plugin_type = query_type_function ();
        g_assert (g_type_is_a (plugin_type, GS_TYPE_PLUGIN));
 


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