[libpeas] Unload plugins in dispose to prevent segv



commit c3361ddd87f193fab071407fabda59391805bf51
Author: Garrett Regier <alias301 gmail com>
Date:   Tue Dec 14 10:35:20 2010 -0800

    Unload plugins in dispose to prevent segv
    
    When unloading plugins in finalize sometimes it would
    cause a segv because we emit a signal on an object
    with a refcount of 0.

 libpeas/peas-engine.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 7b4725e..66bf360 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -392,7 +392,7 @@ peas_engine_get_property (GObject    *object,
 }
 
 static void
-peas_engine_finalize (GObject *object)
+peas_engine_dispose (GObject *object)
 {
   PeasEngine *engine = PEAS_ENGINE (object);
   GList *item;
@@ -407,7 +407,11 @@ peas_engine_finalize (GObject *object)
     }
 
   /* unref the loaders */
-  g_hash_table_destroy (engine->priv->loaders);
+  if (engine->priv->loaders != NULL)
+    {
+      g_hash_table_destroy (engine->priv->loaders);
+      engine->priv->loaders = NULL;
+    }
 
   /* and finally free the infos */
   for (item = engine->priv->plugin_list; item; item = item->next)
@@ -423,6 +427,14 @@ peas_engine_finalize (GObject *object)
       g_slice_free (SearchPath, sp);
     }
 
+  G_OBJECT_CLASS (peas_engine_parent_class)->dispose (object);
+}
+
+static void
+peas_engine_finalize (GObject *object)
+{
+  PeasEngine *engine = PEAS_ENGINE (object);
+
   g_list_free (engine->priv->plugin_list);
   g_list_free (engine->priv->search_paths);
 
@@ -438,6 +450,7 @@ peas_engine_class_init (PeasEngineClass *klass)
   object_class->set_property = peas_engine_set_property;
   object_class->get_property = peas_engine_get_property;
   object_class->constructed = peas_engine_constructed;
+  object_class->dispose = peas_engine_dispose;
   object_class->finalize = peas_engine_finalize;
 
   klass->load_plugin = peas_engine_load_plugin_real;



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