]> Pileus Git - grits/blobdiff - src/grits-plugin.c
More reference counting updates
[grits] / src / grits-plugin.c
index 144c713405bf12c456130798eed7cc9e90744ef2..60b3bbd7280be8d9cddabd7677c9b1ec92e60724 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -127,8 +127,9 @@ GtkWidget *grits_plugin_get_config(GritsPlugin *plugin)
  * Plugins API *
  ***************/
 typedef struct {
-       gchar *name;
+       gchar       *name;
        GritsPlugin *plugin;
+       GModule     *module;
 } GritsPluginStore;
 
 /**
@@ -151,6 +152,14 @@ GritsPlugins *grits_plugins_new(const gchar *dir, GritsPrefs *prefs)
        return plugins;
 }
 
+static void grits_plugins_free_store(GritsPluginStore *store)
+{
+       g_object_unref(store->plugin);
+       //g_module_close(store->module);
+       g_free(store->name);
+       g_free(store);
+}
+
 /**
  * grits_plugins_free:
  * @plugins: the #GritsPlugins to free
@@ -162,12 +171,10 @@ void grits_plugins_free(GritsPlugins *plugins)
        g_debug("GritsPlugins: free");
        for (GList *cur = plugins->plugins; cur; cur = cur->next) {
                GritsPluginStore *store = cur->data;
-               g_debug("GritsPlugin: freeing %s refs=%d->%d", store->name,
+               g_debug("GritsPlugins: freeing %s refs=%d->%d", store->name,
                        G_OBJECT(store->plugin)->ref_count,
                        G_OBJECT(store->plugin)->ref_count-1);
-               g_object_unref(store->plugin);
-               g_free(store->name);
-               g_free(store);
+               grits_plugins_free_store(store);
        }
        g_list_free(plugins->plugins);
        if (plugins->dir)
@@ -270,6 +277,7 @@ GritsPlugin *grits_plugins_load(GritsPlugins *plugins, const char *name,
        GritsPluginStore *store = g_new0(GritsPluginStore, 1);
        store->name = g_strdup(name);
        store->plugin = constructor(viewer, prefs);
+       store->module = module;
        plugins->plugins = g_list_prepend(plugins->plugins, store);
        return store->plugin;
 }
@@ -337,10 +345,8 @@ gboolean grits_plugins_unload(GritsPlugins *plugins, const char *name)
        for (GList *cur = plugins->plugins; cur; cur = cur->next) {
                GritsPluginStore *store = cur->data;
                if (g_str_equal(store->name, name)) {
-                       g_object_unref(store->plugin);
-                       g_free(store->name);
-                       g_free(store);
                        plugins->plugins = g_list_delete_link(plugins->plugins, cur);
+                       grits_plugins_free_store(store);
                }
        }
        return FALSE;