[glib] GDBusConnection: Document memory management semantics for get_property()



commit 0d0a9bb4485069a56caf139346e6a6aad81c4efd
Author: David Zeuthen <davidz redhat com>
Date:   Wed Aug 25 14:45:28 2010 -0400

    GDBusConnection: Document memory management semantics for get_property()
    
    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 |    6 +++++-
 gio/gdbusconnection.h |    4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index fcefb6c..8c3c317 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -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);
 
diff --git a/gio/gdbusconnection.h b/gio/gdbusconnection.h
index 92d477f..d981787 100644
--- a/gio/gdbusconnection.h
+++ b/gio/gdbusconnection.h
@@ -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
  */



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