[jsonrpc-glib] client: tweak panic ordering and add reference



commit a63ae478375d3ac94af2e1dfacb974cc98c3fb40
Author: Christian Hergert <chergert redhat com>
Date:   Thu Dec 28 04:25:24 2017 -0800

    client: tweak panic ordering and add reference
    
    Closing the connection can cause some weird code paths it seems, so try
    to be friendly and hold a reference during the close call. Also, steal
    the invocations first.

 src/jsonrpc-client.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/jsonrpc-client.c b/src/jsonrpc-client.c
index 9a618c7..382ce34 100644
--- a/src/jsonrpc-client.c
+++ b/src/jsonrpc-client.c
@@ -230,14 +230,17 @@ jsonrpc_client_panic (JsonrpcClient *self,
   g_assert (JSONRPC_IS_CLIENT (self));
   g_assert (error != NULL);
 
-  priv->failed = TRUE;
+  g_object_ref (self);
 
-  jsonrpc_client_close (self, NULL, NULL);
+  priv->failed = TRUE;
 
   /* Steal the tasks so that we don't have to worry about reentry. */
   invocations = g_steal_pointer (&priv->invocations);
   priv->invocations = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
 
+  /* Now close the connection */
+  jsonrpc_client_close (self, NULL, NULL);
+
   /*
    * Clear our input and output streams so that new calls
    * fail immediately due to not being connected.
@@ -254,6 +257,8 @@ jsonrpc_client_panic (JsonrpcClient *self,
     g_task_return_error (task, g_error_copy (error));
 
   g_signal_emit (self, signals [FAILED], 0);
+
+  g_object_unref (self);
 }
 
 /*


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