GDBusConnection: Document memory management semantics for get_property()
authorDavid Zeuthen <davidz@redhat.com>
Wed, 25 Aug 2010 18:45:28 +0000 (14:45 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 25 Aug 2010 18:49:05 +0000 (14:49 -0400)
Turns out we are leaking non-floating GVariant instances returned by
get_property() functions.

Also avoid imprecise language such as "newly-allocated GVariant" as
this doesn't specify whether the variant can be floating or not.

Also see https://bugzilla.gnome.org/show_bug.cgi?id=627974 as it is
very related to this change.

Signed-off-by: David Zeuthen <davidz@redhat.com>
gio/gdbusconnection.c
gio/gdbusconnection.h

index fcefb6c..8c3c317 100644 (file)
@@ -3635,7 +3635,8 @@ invoke_get_property_in_idle_cb (gpointer _data)
     {
       g_assert_no_error (error);
 
-      g_variant_ref_sink (value);
+      if (g_variant_is_floating (value))
+        g_variant_ref_sink (value);
       reply = g_dbus_message_new_method_reply (data->message);
       g_dbus_message_set_body (reply, g_variant_new ("(v)", value));
       g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
@@ -3966,10 +3967,13 @@ invoke_get_all_properties_in_idle_cb (gpointer _data)
       if (value == NULL)
         continue;
 
+      if (g_variant_is_floating (value))
+        g_variant_ref_sink (value);
       g_variant_builder_add (&builder,
                              "{sv}",
                              property_info->name,
                              value);
+      g_variant_unref (value);
     }
   g_variant_builder_close (&builder);
 
index 92d477f..d981787 100644 (file)
@@ -221,7 +221,9 @@ typedef void (*GDBusInterfaceMethodCallFunc) (GDBusConnection       *connection,
  *
  * The type of the @get_property function in #GDBusInterfaceVTable.
  *
- * Returns: A newly-allocated #GVariant with the value for @property_name or %NULL if @error is set.
+ * Returns: A #GVariant with the value for @property_name or %NULL if
+ *     @error is set. If the returned #GVariant is floating, it is
+ *     consumed - otherwise its reference count is decreased by one.
  *
  * Since: 2.26
  */