diff --git a/tls/openssl/gtlsclientconnection-openssl.c b/tls/openssl/gtlsclientconnection-openssl.c
index 89c6f24..428cdf4 100644
--- a/tls/openssl/gtlsclientconnection-openssl.c
+++ b/tls/openssl/gtlsclientconnection-openssl.c
@@ -339,7 +339,7 @@ g_tls_client_connection_openssl_client_connection_interface_init (GTlsClientConn
   iface->copy_session_state = g_tls_client_connection_openssl_copy_session_state;
 }
 
-static int data_index;
+static int data_index = -1;
 
 static int
 retrieve_certificate (SSL       *ssl,
@@ -494,7 +494,9 @@ g_tls_client_connection_openssl_initable_init (GInitable       *initable,
       return FALSE;
     }
 
-  data_index = SSL_get_ex_new_index (0, (void *)"gtlsclientconnection", NULL, NULL, NULL);
+  if (data_index == -1) {
+      data_index = SSL_get_ex_new_index (0, (void *)"gtlsclientconnection", NULL, NULL, NULL);
+  }
   SSL_set_ex_data (priv->ssl, data_index, client);
 
 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME