thread-pool: Unref source after mainloop has quit to avoid races in GLib
authorOgnyan Tonchev <ognyan@axis.com>
Thu, 6 Feb 2014 08:03:50 +0000 (09:03 +0100)
committerWim Taymans <wtaymans@redhat.com>
Thu, 6 Feb 2014 08:26:39 +0000 (09:26 +0100)
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=723741

gst/rtsp-server/rtsp-thread-pool.c

index 789d8ff..67c9782 100644 (file)
@@ -56,6 +56,7 @@ typedef struct _GstRTSPThreadImpl
   GstRTSPThread thread;
 
   gint reused;
+  GSource *source;
 } GstRTSPThreadImpl;
 
 GST_DEFINE_MINI_OBJECT_TYPE (GstRTSPThread, gst_rtsp_thread);
@@ -67,6 +68,7 @@ _gst_rtsp_thread_free (GstRTSPThreadImpl * impl)
 {
   GST_DEBUG ("free thread %p", impl);
 
+  g_source_unref (impl->source);
   g_main_loop_unref (impl->thread.loop);
   g_main_context_unref (impl->thread.context);
   g_slice_free1 (sizeof (GstRTSPThreadImpl), impl);
@@ -171,14 +173,11 @@ gst_rtsp_thread_stop (GstRTSPThread * thread)
   GST_DEBUG ("stop thread %p", thread);
 
   if (g_atomic_int_dec_and_test (&impl->reused)) {
-    GSource *source;
-
     GST_DEBUG ("add idle source to quit mainloop of thread %p", thread);
-    source = g_idle_source_new ();
-    g_source_set_callback (source, (GSourceFunc) do_quit,
+    impl->source = g_idle_source_new ();
+    g_source_set_callback (impl->source, (GSourceFunc) do_quit,
         thread, (GDestroyNotify) gst_rtsp_thread_unref);
-    g_source_attach (source, thread->context);
-    g_source_unref (source);
+    g_source_attach (impl->source, thread->context);
   } else
     gst_rtsp_thread_unref (thread);
 }