Fix potential crash in resource_expire()
authorSven Neumann <s.neumann@raumfeld.com>
Mon, 15 Nov 2010 08:58:40 +0000 (09:58 +0100)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 18 Nov 2010 13:02:45 +0000 (15:02 +0200)
GSSDPResourceBrowser emits "resource-unavailable" before it has removed
the resource from its cache. Now if the application changes the cache
in response to this signal emission the code will crash.

Fix this potential crash by emitting the signal after the resource
has been removed from the cache.

libgssdp/gssdp-resource-browser.c

index 43816fe..fb54dbd 100644 (file)
@@ -581,16 +581,23 @@ static gboolean
 resource_expire (gpointer user_data)
 {
         Resource *resource;
+        char *usn;
 
         resource = user_data;
-        
+
+        /* Steal the USN pointer from the resource as we need it for the signal
+         * emission.
+         */
+        usn = resource->usn;
+        resource->usn = NULL;
+
+        g_hash_table_remove (resource->resource_browser->priv->resources, usn);
+
         g_signal_emit (resource->resource_browser,
                        signals[RESOURCE_UNAVAILABLE],
                        0,
-                       resource->usn);
-
-        g_hash_table_remove (resource->resource_browser->priv->resources,
-                             resource->usn);
+                       usn);
+        g_free (usn);
 
         return FALSE;
 }