From e7c7640959be86d3671990437370db8d3575e045 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 1 Feb 2012 20:25:30 +0000 Subject: [PATCH 2/7] TpAccount: ensure that async-returned objects live as long as the result It is valid to keep a GAsyncResult for as long as you like, so it will have to take a copy of the result data. Otherwise, a change as simple as replacing g_simple_async_result_complete with ..._complete_in_idle will result in the data having already been freed by the time the caller sees it. --- telepathy-glib/account.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diff --git a/telepathy-glib/account.c b/telepathy-glib/account.c index a8034a0..8eb3aaf 100644 --- a/telepathy-glib/account.c +++ b/telepathy-glib/account.c @@ -3302,8 +3302,9 @@ _tp_account_got_avatar_cb (TpProxy *proxy, else { avatar = g_value_get_boxed (out_Value); - res = g_value_get_boxed (g_value_array_get_nth (avatar, 0)); - g_simple_async_result_set_op_res_gpointer (result, res, NULL); + res = g_value_dup_boxed (g_value_array_get_nth (avatar, 0)); + g_simple_async_result_set_op_res_gpointer (result, res, + (GDestroyNotify) g_array_unref); } g_simple_async_result_complete (result); @@ -3347,7 +3348,10 @@ tp_account_get_avatar_async (TpAccount *account, * * Finishes an async get operation of @account's avatar. * - * Returns: (element-type guchar): a #GArray of #guchar + * Beware that the returned value is only valid until @result is freed. + * Copy it with g_array_ref() if you need to keep it for longer. + * + * Returns: (element-type guchar) (transfer none): a #GArray of #guchar * containing the bytes of the account's avatar, or %NULL on failure * * Since: 0.9.0 @@ -3774,10 +3778,9 @@ _tp_account_get_storage_specific_information_cb (TpProxy *self, } else { - GHashTable *info; - - info = g_value_get_boxed (value); - g_simple_async_result_set_op_res_gpointer (result, info, NULL); + g_simple_async_result_set_op_res_gpointer (result, + g_value_dup_boxed (value), + (GDestroyNotify) g_hash_table_unref); } g_simple_async_result_complete (result); @@ -3825,6 +3828,9 @@ tp_account_get_storage_specific_information_async (TpAccount *self, * Retrieve the value of the request begun with * tp_account_get_storage_specific_information_async(). * + * Beware that the returned value is only valid until @result is freed. + * Copy it with g_hash_table_ref() if you need to keep it for longer. + * * Returns: (element-type utf8 GObject.Value) (transfer none): a #GHashTable * of strings to GValues representing the D-Bus type a{sv}. * -- 1.7.9