rtsp-media-factory: g_signal_connect_object is not thread safe, can't use it here
authorOlivier Crête <olivier.crete@collabora.com>
Fri, 22 Mar 2013 22:25:07 +0000 (18:25 -0400)
committerOlivier Crête <olivier.crete@collabora.com>
Fri, 22 Mar 2013 22:59:50 +0000 (18:59 -0400)
Instead use a GWeakRef which is safe to use

This is a known GLib bug, see:
https://bugzilla.gnome.org/show_bug.cgi?id=667145

gst/rtsp-server/rtsp-media-factory.c

index ced81ec..f448276 100644 (file)
@@ -646,13 +646,37 @@ compare_media (gpointer key, GstRTSPMedia * media1, GstRTSPMedia * media2)
 }
 
 static void
-media_unprepared (GstRTSPMedia * media, GstRTSPMediaFactory * factory)
+media_unprepared (GstRTSPMedia * media, GWeakRef * ref)
 {
-  GstRTSPMediaFactoryPrivate *priv = factory->priv;;
+  GstRTSPMediaFactory *factory = g_weak_ref_get (ref);
+  GstRTSPMediaFactoryPrivate *priv;
+
+  if (!factory)
+    return;
+
+  priv = factory->priv;;
 
   g_mutex_lock (&priv->medias_lock);
   g_hash_table_foreach_remove (priv->medias, (GHRFunc) compare_media, media);
   g_mutex_unlock (&priv->medias_lock);
+
+  g_object_unref (factory);
+}
+
+static GWeakRef *
+weak_ref_new (gpointer obj)
+{
+  GWeakRef *ref = g_slice_new (GWeakRef);
+
+  g_weak_ref_init (ref, obj);
+  return ref;
+}
+
+static void
+weak_ref_free (GWeakRef * ref)
+{
+  g_weak_ref_clear (ref);
+  g_slice_free (GWeakRef, ref);
 }
 
 /**
@@ -733,8 +757,9 @@ gst_rtsp_media_factory_construct (GstRTSPMediaFactory * factory,
       if (!gst_rtsp_media_is_reusable (media)) {
         /* when not reusable, connect to the unprepare signal to remove the item
          * from our cache when it gets unprepared */
-        g_signal_connect_object (media, "unprepared",
-            (GCallback) media_unprepared, factory, 0);
+        g_signal_connect_data (media, "unprepared",
+            (GCallback) media_unprepared, weak_ref_new (factory),
+            (GClosureNotify) weak_ref_free, 0);
       }
     }
   }