[gupnp] [PATCH] Fix potential crash in resource_expire()



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 |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/libgssdp/gssdp-resource-browser.c b/libgssdp/gssdp-resource-browser.c
index 43816fe..78dc384 100644
--- a/libgssdp/gssdp-resource-browser.c
+++ b/libgssdp/gssdp-resource-browser.c
@@ -581,16 +581,24 @@ static gboolean
 resource_expire (gpointer user_data)
 {
         Resource *resource;
+        gchar *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);
+
+        /*  emit the signal after having removed the resource from the cache  */
         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;
 }
-- 
1.7.1

--
To unsubscribe send a mail to gupnp+unsubscribe\@o-hand.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]