[jsonrpc-glib/jsonrpc-glib-3-28] client: properly sink floating references
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jsonrpc-glib/jsonrpc-glib-3-28] client: properly sink floating references
- Date: Sat, 28 Jul 2018 02:42:03 +0000 (UTC)
commit 0a78f9d8a15ce31ebd4fc86280711777e810ce53
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 0cfaec4..6f3d748 100644
--- a/src/jsonrpc-client.c
+++ b/src/jsonrpc-client.c
@@ -963,6 +963,7 @@ jsonrpc_client_call_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;
@@ -975,6 +976,13 @@ jsonrpc_client_call_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));
@@ -991,11 +999,6 @@ jsonrpc_client_call_async (JsonrpcClient *self,
g_task_set_task_data (task, GINT_TO_POINTER (id), 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", id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]