GUACAMOLE-157: Merge fix for segfault upon VNC disconnect.
diff --git a/src/common-ssh/guac_ssh.c b/src/common-ssh/guac_ssh.c
index 2c59e1d..488eea2 100644
--- a/src/common-ssh/guac_ssh.c
+++ b/src/common-ssh/guac_ssh.c
@@ -48,7 +48,7 @@
 /**
  * Array of mutexes, used by OpenSSL.
  */
-static pthread_mutex_t* guac_common_ssh_openssl_locks;
+static pthread_mutex_t* guac_common_ssh_openssl_locks = NULL;
 
 /**
  * Called by OpenSSL when locking or unlocking the Nth mutex.
@@ -103,7 +103,7 @@
 
     /* Allocate required number of locks */
     guac_common_ssh_openssl_locks =
-        malloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks());
+        malloc(sizeof(pthread_mutex_t) * count);
 
     /* Initialize each lock */
     for (i=0; i < count; i++)
@@ -121,6 +121,10 @@
 
     int i;
 
+    /* SSL lock array was not initialized */
+    if (guac_common_ssh_openssl_locks == NULL)
+        return;
+
     /* Free all locks */
     for (i=0; i < count; i++)
         pthread_mutex_destroy(&(guac_common_ssh_openssl_locks[i]));