core: Cancel HTTPResponse SoupServer goes away
authorJens Georg <mail@jensge.org>
Mon, 19 Sep 2011 10:11:46 +0000 (12:11 +0200)
committerJens Georg <mail@jensge.org>
Mon, 19 Sep 2011 10:13:47 +0000 (12:13 +0200)
Adding a week reference to cancel the HTTPGstSink in case the
SoupServer is gone. Otherwise the sink is stuck on the wait
condition forever, leaking the HTTPResponse.

src/rygel/rygel-http-response.vala

index ecc75fa..a6309c6 100644 (file)
@@ -59,6 +59,7 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
 
     private Pipeline pipeline;
     private uint bus_watch_id;
+    private bool unref_soup_server;
 
     public HTTPResponse (HTTPGet        request,
                          HTTPGetHandler request_handler,
@@ -87,6 +88,14 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.msg.response_body.set_accumulate (false);
 
         this.prepare_pipeline ("RygelHTTPGstResponse", src);
+        this.server.weak_ref (this.on_server_weak_ref);
+        this.unref_soup_server = true;
+    }
+
+    ~HTTPResponse () {
+        if (this.unref_soup_server) {
+            this.server.weak_unref (this.on_server_weak_ref);
+        }
     }
 
     public async void run () {
@@ -137,6 +146,11 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.end (true, Soup.KnownStatusCode.CANCELLED);
     }
 
+    private void on_server_weak_ref (GLib.Object object) {
+        this.needs_weak_unref = false;
+        this.cancellable.cancel ();
+    }
+
     private void prepare_pipeline (string name, Element src) throws Error {
         var sink = new HTTPGstSink (this);