@@ -2774,6 +2774,7 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
27742774#ifdef WOLFSSL_STATIC_MEMORY
27752775static void SSL_CtxResourceFreeStaticMem(void* heap)
27762776{
2777+ #ifndef SINGLE_THREADED
27772778 if (heap != NULL
27782779 #ifdef WOLFSSL_HEAP_TEST
27792780 /* avoid dereferencing a test value */
@@ -2784,6 +2785,9 @@ static void SSL_CtxResourceFreeStaticMem(void* heap)
27842785 WOLFSSL_HEAP* mem = hint->memory;
27852786 wc_FreeMutex(&mem->memory_mutex);
27862787 }
2788+ #else
2789+ (void)heap;
2790+ #endif
27872791}
27882792#endif /* WOLFSSL_STATIC_MEMORY */
27892793
@@ -7235,6 +7239,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
72357239
72367240 ssl_hint->memory = ctx_hint->memory;
72377241 #ifndef WOLFSSL_STATIC_MEMORY_LEAN
7242+ #ifndef SINGLE_THREADED
72387243 /* lock and check IO count / handshake count */
72397244 if (wc_LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) {
72407245 WOLFSSL_MSG("Bad memory_mutex lock");
@@ -7243,10 +7248,13 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
72437248 WOLFSSL_ERROR_VERBOSE(BAD_MUTEX_E);
72447249 return BAD_MUTEX_E;
72457250 }
7251+ #endif
72467252 if (ctx_hint->memory->maxHa > 0 &&
72477253 ctx_hint->memory->maxHa <= ctx_hint->memory->curHa) {
72487254 WOLFSSL_MSG("At max number of handshakes for static memory");
7255+ #ifndef SINGLE_THREADED
72497256 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7257+ #endif
72507258 XFREE(ssl->heap, ctx->heap, DYNAMIC_TYPE_SSL);
72517259 ssl->heap = NULL; /* free and set to NULL for IO counter */
72527260 return MEMORY_E;
@@ -7255,15 +7263,19 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
72557263 if (ctx_hint->memory->maxIO > 0 &&
72567264 ctx_hint->memory->maxIO <= ctx_hint->memory->curIO) {
72577265 WOLFSSL_MSG("At max number of IO allowed for static memory");
7266+ #ifndef SINGLE_THREADED
72587267 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7268+ #endif
72597269 XFREE(ssl->heap, ctx->heap, DYNAMIC_TYPE_SSL);
72607270 ssl->heap = NULL; /* free and set to NULL for IO counter */
72617271 return MEMORY_E;
72627272 }
72637273 ctx_hint->memory->curIO++;
72647274 ctx_hint->memory->curHa++;
72657275 ssl_hint->haFlag = 1;
7276+ #ifndef SINGLE_THREADED
72667277 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7278+ #endif
72677279
72687280 /* check if tracking stats */
72697281 if (ctx_hint->memory->flag & WOLFMEM_TRACK_STATS) {
@@ -7277,25 +7289,35 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
72777289
72787290 /* check if using fixed IO buffers */
72797291 if (ctx_hint->memory->flag & WOLFMEM_IO_POOL_FIXED) {
7292+ #ifndef SINGLE_THREADED
72807293 if (wc_LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) {
72817294 WOLFSSL_MSG("Bad memory_mutex lock");
72827295 WOLFSSL_ERROR_VERBOSE(BAD_MUTEX_E);
72837296 return BAD_MUTEX_E;
72847297 }
7298+ #endif
72857299 if (SetFixedIO(ctx_hint->memory, &(ssl_hint->inBuf)) != 1) {
7300+ #ifndef SINGLE_THREADED
72867301 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7302+ #endif
72877303 return MEMORY_E;
72887304 }
72897305 if (SetFixedIO(ctx_hint->memory, &(ssl_hint->outBuf)) != 1) {
7306+ #ifndef SINGLE_THREADED
72907307 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7308+ #endif
72917309 return MEMORY_E;
72927310 }
72937311 if (ssl_hint->outBuf == NULL || ssl_hint->inBuf == NULL) {
72947312 WOLFSSL_MSG("Not enough memory to create fixed IO buffers");
7313+ #ifndef SINGLE_THREADED
72957314 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7315+ #endif
72967316 return MEMORY_E;
72977317 }
7318+ #ifndef SINGLE_THREADED
72987319 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
7320+ #endif
72997321 }
73007322 #endif /* !WOLFSSL_STATIC_MEMORY_LEAN */
73017323 #ifdef WOLFSSL_HEAP_TEST
0 commit comments