ges: Give a reference to the formatter for the idle callback
authorThibault Saunier <thibault.saunier@collabora.com>
Fri, 14 Feb 2014 12:20:31 +0000 (13:20 +0100)
committerThibault Saunier <thibault.saunier@collabora.com>
Sun, 16 Feb 2014 19:58:04 +0000 (20:58 +0100)
This avoid segfault as we are not guaranteed that the formatter will
not be destroyed in the meantime.

+ Minor cleanup of handling of private members

https://bugzilla.gnome.org/show_bug.cgi?id=724337

ges/ges-base-xml-formatter.c

index 23f6ef7..5edb89d 100644 (file)
@@ -29,9 +29,10 @@ G_DEFINE_ABSTRACT_TYPE (GESBaseXmlFormatter, ges_base_xml_formatter,
     GES_TYPE_FORMATTER);
 
 #define _GET_PRIV(o)\
-  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GES_TYPE_BASE_XML_FORMATTER, GESBaseXmlFormatterPrivate))
+  (((GESBaseXmlFormatter*) o)->priv)
 
-static void _loading_done (GESFormatter * self);
+
+static gboolean _loading_done_cb (GESFormatter * self);
 
 typedef struct PendingEffects
 {
@@ -235,7 +236,7 @@ _load_from_uri (GESFormatter * self, GESTimeline * timeline, const gchar * uri,
 
   if (g_hash_table_size (priv->assetid_pendingclips) == 0 &&
       priv->pending_assets == NULL)
-    g_idle_add ((GSourceFunc) _loading_done, self);
+    g_idle_add ((GSourceFunc) _loading_done_cb, g_object_ref (self));
 
   return TRUE;
 }
@@ -346,7 +347,12 @@ _finalize (GObject * object)
 static void
 ges_base_xml_formatter_init (GESBaseXmlFormatter * self)
 {
-  GESBaseXmlFormatterPrivate *priv = _GET_PRIV (self);
+  GESBaseXmlFormatterPrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+      GES_TYPE_BASE_XML_FORMATTER, GESBaseXmlFormatterPrivate);
+
+  priv = self->priv;
 
   priv->check_only = FALSE;
   priv->parsecontext = NULL;
@@ -411,7 +417,7 @@ _set_auto_transition (gpointer prio, LayerEntry * entry, gpointer udata)
 static void
 _loading_done (GESFormatter * self)
 {
-  GESBaseXmlFormatterPrivate *priv = _GET_PRIV (self);
+  GESBaseXmlFormatterPrivate *priv = GES_BASE_XML_FORMATTER (self)->priv;
 
   if (priv->parsecontext)
     g_markup_parse_context_free (priv->parsecontext);
@@ -424,6 +430,15 @@ _loading_done (GESFormatter * self)
   ges_project_set_loaded (self->project, self);
 }
 
+static gboolean
+_loading_done_cb (GESFormatter * self)
+{
+  _loading_done (self);
+  g_object_unref (self);
+
+  return FALSE;
+}
+
 static void
 _set_child_property (GQuark field_id, const GValue * value,
     GESTrackElement * effect)