diff --git a/c/src/point_one/polaris/polaris.c b/c/src/point_one/polaris/polaris.c index c4ffd3c..a75107c 100644 --- a/c/src/point_one/polaris/polaris.c +++ b/c/src/point_one/polaris/polaris.c @@ -387,7 +387,10 @@ void Polaris_Disconnect(PolarisContext_t* context) { P1_DebugPrint("Closing Polaris connection.\n"); context->disconnected = 1; #ifdef POLARIS_USE_TLS - SSL_shutdown(context->ssl); + if (pthread_mutex_init(&context->ssl_mutex, NULL) != NULL){ + SSL_shutdown(context->ssl); + pthread_mutex_destroy(&context->ssl_mutex); + } #endif shutdown(context->socket, SHUT_RDWR); // Note: We intentionally close the socket here but do _not_ destroy the SSL @@ -882,13 +885,16 @@ static int OpenSocket(PolarisContext_t* context, const char* endpoint_url, void CloseSocket(PolarisContext_t* context, int destroy_context) { #ifdef POLARIS_USE_TLS if (destroy_context && context->ssl != NULL) { - if (SSL_get_shutdown(context->ssl) == 0) { - SSL_shutdown(context->ssl); + if (pthread_mutex_init(&context->ssl_mutex, NULL) != NULL){ + if (SSL_get_shutdown(context->ssl) == 0) { + SSL_shutdown(context->ssl); + } + SSL_free(context->ssl); + } + context->ssl = NULL; + pthread_mutex_destroy(&context->ssl_mutex); + } } - - SSL_free(context->ssl); - context->ssl = NULL; - } #endif if (context->socket != P1_INVALID_SOCKET) { diff --git a/c/src/point_one/polaris/polaris.h b/c/src/point_one/polaris/polaris.h index 92cc030..01138b1 100644 --- a/c/src/point_one/polaris/polaris.h +++ b/c/src/point_one/polaris/polaris.h @@ -120,6 +120,7 @@ struct PolarisContext_s { // header file. void* ssl_ctx; void* ssl; + pthread_mutex_t context_lock; }; #ifdef __cplusplus