[PATCH 1/2] gupnp-service: don't hold a reference on ourselves



GUPnPService used to hold a reference on itself for the run-time of
the initial asynchronous introspection. Due to this reference the
object can't be disposed until this call has finished. Now if you
create a device with services and immidiately destroy it, the
service will still be alive holding a pointer to the XML device
description that is not any longer valid. This leads to a crash
when the asynchronous introspection finishes.

Fix this crash by not keeping a reference on ourselves. The pending
introspection is then cancelled from the dispose handler.
---
 libgupnp/gupnp-service.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index 1913c7d..64f5673 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -1312,13 +1312,11 @@ got_introspection (GUPnPServiceInfo          *info,
                    const GError              *error,
                    gpointer                   user_data)
 {
-        GUPnPService *service;
+        GUPnPService *service = GUPNP_SERVICE (info);
         const GList *state_variables, *l;
         GHashTableIter iter;
         gpointer data;
 
-        service = GUPNP_SERVICE (user_data);
-
         if (introspection) {
                 state_variables =
                         gupnp_service_introspection_list_state_variables
@@ -1347,8 +1345,6 @@ got_introspection (GUPnPServiceInfo          *info,
 
         while (g_hash_table_iter_next (&iter, NULL, &data))
                 send_initial_state ((SubscriptionData *) data);
-
-        g_object_unref (service);
 }
 
 static char *
@@ -1389,8 +1385,7 @@ gupnp_service_constructor (GType                  type,
         /* Get introspection and save state variable names */
         gupnp_service_info_get_introspection_async (info,
                                                     got_introspection,
-                                                    object);
-        g_object_ref (object);
+                                                    NULL);
 
         /* Get server */
         context = gupnp_service_info_get_context (info);
-- 
1.7.1



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