free ctx in case of InitMutex fail

This commit is contained in:
Jacob Barthelmeh
2016-06-28 09:29:28 -06:00
parent 7da797dd4c
commit 0589fe0d39
3 changed files with 13 additions and 0 deletions

View File

@ -1376,6 +1376,7 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
if (InitMutex(&ctx->countMutex) < 0) {
WOLFSSL_MSG("Mutex error on CTX init");
ctx->err = (int)CTX_INIT_MUTEX_E;
return BAD_MUTEX_E;
}
@ -1537,6 +1538,13 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
if (LockMutex(&ctx->countMutex) != 0) {
WOLFSSL_MSG("Couldn't lock count mutex");
/* check error state, if mutex error code then mutex init failed but
* CTX was still malloc'd */
if (ctx->err == (int)CTX_INIT_MUTEX_E) {
SSL_CtxResourceFree(ctx);
XFREE(ctx, ctx->heap, DYNAMIC_TYPE_CTX);
}
return;
}
ctx->refCount--;
@ -11344,6 +11352,9 @@ const char* wolfSSL_ERR_reason_error_string(unsigned long e)
case INPUT_SIZE_E:
return "Input size too large Error";
case CTX_INIT_MUTEX_E:
return "Initialize ctx mutex error";
default :
return "unknown error number";
}

View File

@ -149,6 +149,7 @@ enum wolfSSL_ErrorCodes {
DTLS_EXPORT_VER_E = -411, /* export version error */
INPUT_SIZE_E = -412, /* input size too big error */
CTX_INIT_MUTEX_E = -413, /* initialize ctx mutex error */
/* add strings to wolfSSL_ERR_reason_error_string in internal.c !!!!! */
/* begin negotiation parameter errors */

View File

@ -1922,6 +1922,7 @@ struct WOLFSSL_CTX {
WOLFSSL_METHOD* method;
wolfSSL_Mutex countMutex; /* reference count mutex */
int refCount; /* reference count */
int err; /* error code in case of mutex not created */
#ifndef NO_DH
buffer serverDH_P;
buffer serverDH_G;