[jsonrpc-glib] client: properly sink floating references
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jsonrpc-glib] client: properly sink floating references
- Date: Sat, 28 Jul 2018 02:40:52 +0000 (UTC)
commit ea9540bf99dac12c0b19d5f0c7fdfd091130b735
Author: Christian Hergert <chergert redhat com>
Date: Fri Jul 27 19:39:05 2018 -0700
client: properly sink floating references
This fixes an issue where we would not actually consume the floating
reference that we expected to in g_variant_dict_insert_value().
src/jsonrpc-client.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/src/jsonrpc-client.c b/src/jsonrpc-client.c
index d9ca04b..1b9f56a 100644
--- a/src/jsonrpc-client.c
+++ b/src/jsonrpc-client.c
@@ -971,6 +971,7 @@ jsonrpc_client_call_with_id_async (JsonrpcClient *self,
{
JsonrpcClientPrivate *priv = jsonrpc_client_get_instance_private (self);
g_autoptr(GVariant) message = NULL;
+ g_autoptr(GVariant) sunk_variant = NULL;
g_autoptr(GTask) task = NULL;
g_autoptr(GError) error = NULL;
GVariantDict dict;
@@ -986,6 +987,13 @@ jsonrpc_client_call_with_id_async (JsonrpcClient *self,
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, jsonrpc_client_call_async);
+ if (params == NULL)
+ params = g_variant_new_maybe (G_VARIANT_TYPE_VARIANT, NULL);
+
+ /* If we got a floating reference, we should consume it */
+ if (g_variant_is_floating (params))
+ sunk_variant = g_variant_ref_sink (params);
+
if (!jsonrpc_client_check_ready (self, &error))
{
g_task_return_error (task, g_steal_pointer (&error));
@@ -1002,11 +1010,6 @@ jsonrpc_client_call_with_id_async (JsonrpcClient *self,
g_task_set_task_data (task, GINT_TO_POINTER (idval), NULL);
- /* Use empty maybe type for NULL, and floating reference will
- * be consumed by g_variant_dict_insert_value() below. */
- if (params == NULL)
- params = g_variant_new_maybe (G_VARIANT_TYPE_VARIANT, NULL);
-
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "jsonrpc", "s", "2.0");
g_variant_dict_insert (&dict, "id", "x", idval);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]