souphttpsrc: Always abort the session once its last user is gone
authorSebastian Dröge <sebastian@centricular.com>
Sat, 29 Jan 2022 10:55:30 +0000 (12:55 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 29 Jan 2022 16:22:48 +0000 (16:22 +0000)
And wait until there are no pending GSources on the main context anymore
afterwards.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1603>

subprojects/gst-plugins-good/ext/soup/gstsouphttpsrc.c

index a488b06..7204c1b 100644 (file)
@@ -125,7 +125,6 @@ _soup_session_finalize_cb (gpointer user_data)
 {
   GstSoupSession *sess = user_data;
 
-  g_clear_object (&sess->session);
   g_main_loop_quit (sess->loop);
 
   return FALSE;
@@ -1064,6 +1063,13 @@ thread_func (gpointer user_data)
 
   g_main_loop_run (session->loop);
 
+  /* Abort any pending operations on the session ... */
+  _soup_session_abort (session->session);
+  g_clear_object (&session->session);
+
+  /* ... and iterate the main context until nothing is pending anymore */
+  while (g_main_context_iteration (ctx, FALSE));
+
   g_main_context_pop_thread_default (ctx);
 
   GST_DEBUG_OBJECT (session, "thread stop");
@@ -1215,9 +1221,6 @@ _session_close_cb (gpointer user_data)
     g_clear_object (&src->msg);
   }
 
-  if (!src->session_is_shared)
-    _soup_session_abort (src->session->session);
-
   /* there may be multiple of this callback attached to the session,
    * each with different data pointer; disconnect the one we are closing
    * the session for, leave the others alone