[libpeas: 1/18] Free the loaded plugins hash table in the Seed loader



commit 5241a06c1480838ea7eb69deac82a48ab42eed99
Author: Garrett Regier <alias301 gmail com>
Date:   Mon Feb 21 03:02:11 2011 -0800

    Free the loaded plugins hash table in the Seed loader

 loaders/seed/peas-plugin-loader-seed.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/loaders/seed/peas-plugin-loader-seed.c b/loaders/seed/peas-plugin-loader-seed.c
index 73a303e..a7a9820 100644
--- a/loaders/seed/peas-plugin-loader-seed.c
+++ b/loaders/seed/peas-plugin-loader-seed.c
@@ -241,9 +241,6 @@ peas_plugin_loader_seed_unload (PeasPluginLoader *loader,
     return;
 
   g_hash_table_remove (sloader->loaded_plugins, info);
-  seed_value_unprotect (sinfo->context, sinfo->extensions);
-  seed_context_unref (sinfo->context);
-  g_slice_free (SeedInfo, sinfo);
 }
 
 static void
@@ -253,6 +250,15 @@ peas_plugin_loader_seed_garbage_collect (PeasPluginLoader *loader)
 }
 
 static void
+destroy_seed_info (SeedInfo *info)
+{
+  seed_value_unprotect (info->context, info->extensions);
+  seed_context_unref (info->context);
+
+  g_slice_free (SeedInfo, info);
+}
+
+static void
 peas_plugin_loader_seed_init (PeasPluginLoaderSeed *sloader)
 {
   /* This is somewhat buggy as the seed engine cannot be reinitialized
@@ -261,14 +267,29 @@ peas_plugin_loader_seed_init (PeasPluginLoaderSeed *sloader)
   if (!seed)
     seed = seed_init (NULL, NULL);
 
-  sloader->loaded_plugins = g_hash_table_new (g_direct_hash, g_direct_equal);
+  sloader->loaded_plugins = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+                                                   NULL,
+                                                   (GDestroyNotify) destroy_seed_info);
+}
+
+static void
+peas_plugin_loader_seed_finalize (GObject *object)
+{
+  PeasPluginLoaderSeed *sloader = PEAS_PLUGIN_LOADER_SEED (object);
+
+  g_hash_table_destroy (sloader->loaded_plugins);
+
+  G_OBJECT_CLASS (peas_plugin_loader_seed_parent_class)->finalize (object);
 }
 
 static void
 peas_plugin_loader_seed_class_init (PeasPluginLoaderSeedClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   PeasPluginLoaderClass *loader_class = PEAS_PLUGIN_LOADER_CLASS (klass);
 
+  object_class->finalize = peas_plugin_loader_seed_finalize;
+
   loader_class->add_module_directory = peas_plugin_loader_seed_add_module_directory;
   loader_class->load = peas_plugin_loader_seed_load;
   loader_class->provides_extension = peas_plugin_loader_seed_provides_extension;



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