diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-01 20:25:30 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-02-09 13:06:08 +0000 |
commit | 8063df40a53ffb596b481b038716aac89f87ba00 (patch) | |
tree | 199688826a90a67b9b5a550d82cfb50ec6a46b39 | |
parent | f745ccc6d2fb1fcd3f8bb0c74a1f1d649f1a0870 (diff) | |
download | telepathy-glib-8063df40a53ffb596b481b038716aac89f87ba00.tar.gz |
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.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=45554
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | 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 a8034a0f6..8eb3aaf65 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}. * |