Fix object lifecycle errors.
[platform/core/uifw/at-spi2-atk.git] / droute / droute.c
index 5b749ae..8c7bd51 100644 (file)
@@ -249,6 +249,8 @@ impl_prop_GetAll (DBusMessage *message,
     gchar *iface;
 
     void  *datum = path_get_datum (path, pathstr);
+    if (!datum)
+       return NULL;
 
     dbus_error_init (&error);
     if (!dbus_message_get_args
@@ -299,6 +301,7 @@ impl_prop_GetSet (DBusMessage *message,
     StrPair pair;
     PropertyPair *prop_funcs = NULL;
 
+    void *datum;
 
     dbus_error_init (&error);
     if (!dbus_message_get_args (message,
@@ -310,29 +313,38 @@ impl_prop_GetSet (DBusMessage *message,
                                 DBUS_TYPE_INVALID))
         return dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
 
+    _DROUTE_DEBUG ("DRoute (handle prop): %s|%s on %s\n", pair.one, pair.two, pathstr);
+
     prop_funcs = (PropertyPair *) g_hash_table_lookup (path->properties, &pair);
     if (!prop_funcs)
         return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
 
+    datum = path_get_datum (path, pathstr);
+    if (!datum)
+       return NULL;
+
     if (get && prop_funcs->get)
       {
-        void *datum = path_get_datum (path, pathstr);
+        
         DBusMessageIter iter;
 
         _DROUTE_DEBUG ("DRoute (handle prop Get): %s|%s on %s\n", pair.one, pair.two, pathstr);
 
         reply = dbus_message_new_method_return (message);
         dbus_message_iter_init_append (reply, &iter);
-        (prop_funcs->get) (&iter, datum);
+        if (!(prop_funcs->get) (&iter, datum))
+         {
+           dbus_message_unref (reply);
+            reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Get failed");
+         }
       }
     else if (!get && prop_funcs->set)
       {
-        void *datum = path_get_datum (path, pathstr);
         DBusMessageIter iter;
 
         _DROUTE_DEBUG ("DRoute (handle prop Get): %s|%s on %s\n", pair.one, pair.two, pathstr);
 
-        dbus_message_iter_init_append (message, &iter);
+        dbus_message_iter_init (message, &iter);
         /* Skip the interface and property name */
         dbus_message_iter_next(&iter);
         dbus_message_iter_next(&iter);
@@ -443,6 +455,7 @@ handle_introspection (DBusConnection *bus,
     for (i=0; i < path->interfaces->len; i++)
       {
         gchar *interface = (gchar *) g_ptr_array_index (path->interfaces, i);
+        _DROUTE_DEBUG ("DRoute (appending interface): %s\n", interface);
         append_interface(output, interface, path->cnx->introspect_dir);
       }
 
@@ -475,27 +488,40 @@ handle_other (DBusConnection *bus,
 
     StrPair pair;
     DRouteFunction func;
-    DBusMessage *reply;
+    DBusMessage *reply = NULL;
+
+    void *datum;
 
     pair.one = iface;
     pair.two = member;
 
     _DROUTE_DEBUG ("DRoute (handle other): %s|%s on %s\n", member, iface, pathstr);
 
+    datum = path_get_datum (path, pathstr);
+    if (!datum)
+       return result;
+
     func = (DRouteFunction) g_hash_table_lookup (path->methods, &pair);
     if (func != NULL)
       {
-        void *datum = path_get_datum (path, pathstr);
 
         reply = (func) (bus, message, datum);
 
-        if (reply)
+        if (!reply)
           {
-            dbus_connection_send (bus, reply, NULL);
-            dbus_message_unref (reply);
+            /* All D-Bus method calls must have a reply.
+             * If one is not provided presume that the call has a void
+             * return and no error has occured.
+             */
+            reply = dbus_message_new_method_return (message);
           }
+        dbus_connection_send (bus, reply, NULL);
+        dbus_message_unref (reply);
         result = DBUS_HANDLER_RESULT_HANDLED;
       }
+
+    _DROUTE_DEBUG ("DRoute (handle other) (reply): type %d\n",
+                   dbus_message_get_type(reply));
     return result;
 }
 
@@ -510,6 +536,8 @@ handle_message (DBusConnection *bus, DBusMessage *message, void *user_data)
     const gint   type    = dbus_message_get_type (message);
     const gchar *pathstr = dbus_message_get_path (message);
 
+    _DROUTE_DEBUG ("DRoute (handle message): %s|%s of type %d on %s\n", member, iface, type, pathstr);
+
     /* Check for basic reasons not to handle */
     if (type   != DBUS_MESSAGE_TYPE_METHOD_CALL ||
         member == NULL ||