From 605811dbb15450037befa3e3b120f737f4625752 Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Thu, 6 Apr 2017 17:24:50 +0100
Subject: [PATCH] Fix crash when opening connection from a GSocketAddress

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 5368f77d6215d7b6ad1422dff284d288a26ff481)
---
 src/vncconnection.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/vncconnection.c b/src/vncconnection.c
index c55f71d..8cec1af 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -5423,13 +5423,13 @@ static gboolean vnc_connection_open_addr_internal(VncConnection *conn)
     VNC_DEBUG("Connecting with addr %p", priv->addr);
 
     sock = vnc_connection_connect_socket(&priv->wait, priv->addr, &conn_error);
-    vnc_connection_set_error(conn, "Unable to connect: %s",
-                             conn_error->message);
-    g_clear_error(&conn_error);
     if (sock) {
         priv->sock = sock;
         return TRUE;
     }
+    vnc_connection_set_error(conn, "Unable to connect: %s",
+                             conn_error ? conn_error->message : "");
+    g_clear_error(&conn_error);
     return FALSE;
 }
 
