@@ -7241,6 +7241,8 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
72417241 ssl_hint = ((WOLFSSL_HEAP_HINT*)(ssl->heap));
72427242 ctx_hint = ((WOLFSSL_HEAP_HINT*)(ctx->heap));
72437243
7244+ ssl_hint->memory = ctx_hint->memory;
7245+ #ifndef WOLFSSL_LEAN_STATIC_MEMORY
72447246 /* lock and check IO count / handshake count */
72457247 if (wc_LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) {
72467248 WOLFSSL_MSG("Bad memory_mutex lock");
@@ -7268,7 +7270,6 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
72687270 }
72697271 ctx_hint->memory->curIO++;
72707272 ctx_hint->memory->curHa++;
7271- ssl_hint->memory = ctx_hint->memory;
72727273 ssl_hint->haFlag = 1;
72737274 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
72747275
@@ -7304,6 +7305,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
73047305 }
73057306 wc_UnLockMutex(&(ctx_hint->memory->memory_mutex));
73067307 }
7308+ #endif /* !WOLFSSL_LEAN_STATIC_MEMORY */
73077309 #ifdef WOLFSSL_HEAP_TEST
73087310 }
73097311 #endif
@@ -8382,30 +8384,38 @@ void SSL_ResourceFree(WOLFSSL* ssl)
83828384 /* avoid dereferencing a test value */
83838385 if (ssl->heap != (void*)WOLFSSL_HEAP_TEST) {
83848386 #endif
8387+ void* heap = ssl->ctx ? ssl->ctx->heap : ssl->heap;
8388+ #ifndef WOLFSSL_LEAN_STATIC_MEMORY
83858389 WOLFSSL_HEAP_HINT* ssl_hint = (WOLFSSL_HEAP_HINT*)ssl->heap;
83868390 WOLFSSL_HEAP* ctx_heap;
8387- void* heap = ssl->ctx ? ssl->ctx->heap : ssl->heap;
83888391
83898392 ctx_heap = ssl_hint->memory;
8393+ #ifndef SINGLE_THREADED
83908394 if (wc_LockMutex(&(ctx_heap->memory_mutex)) != 0) {
83918395 WOLFSSL_MSG("Bad memory_mutex lock");
83928396 }
8397+ #endif
83938398 ctx_heap->curIO--;
83948399 if (FreeFixedIO(ctx_heap, &(ssl_hint->outBuf)) != 1) {
83958400 WOLFSSL_MSG("Error freeing fixed output buffer");
83968401 }
83978402 if (FreeFixedIO(ctx_heap, &(ssl_hint->inBuf)) != 1) {
83988403 WOLFSSL_MSG("Error freeing fixed output buffer");
83998404 }
8400- if (ssl_hint->haFlag && ctx_heap->curHa > 0) { /* check if handshake count has been decreased*/
8405+
8406+ /* check if handshake count has been decreased*/
8407+ if (ssl_hint->haFlag && ctx_heap->curHa > 0) {
84018408 ctx_heap->curHa--;
84028409 }
8410+ #ifndef SINGLE_THREADED
84038411 wc_UnLockMutex(&(ctx_heap->memory_mutex));
8412+ #endif
84048413
84058414 /* check if tracking stats */
84068415 if (ctx_heap->flag & WOLFMEM_TRACK_STATS) {
84078416 XFREE(ssl_hint->stats, heap, DYNAMIC_TYPE_SSL);
84088417 }
8418+ #endif /* !WOLFSSL_LEAN_STATIC_MEMORY */
84098419 XFREE(ssl->heap, heap, DYNAMIC_TYPE_SSL);
84108420 #ifdef WOLFSSL_HEAP_TEST
84118421 }
@@ -8673,14 +8683,20 @@ void FreeHandshakeResources(WOLFSSL* ssl)
86738683 WOLFSSL_HEAP* ctx_heap;
86748684
86758685 ctx_heap = ssl_hint->memory;
8686+ #ifndef SINGLE_THREADED
86768687 if (wc_LockMutex(&(ctx_heap->memory_mutex)) != 0) {
86778688 WOLFSSL_MSG("Bad memory_mutex lock");
86788689 }
8690+ #endif
8691+ #ifndef WOLFSSL_LEAN_STATIC_MEMORY
86798692 if (ctx_heap->curHa > 0) {
86808693 ctx_heap->curHa--;
86818694 }
86828695 ssl_hint->haFlag = 0; /* set to zero since handshake has been dec */
8696+ #endif
8697+ #ifndef SINGLE_THREADED
86838698 wc_UnLockMutex(&(ctx_heap->memory_mutex));
8699+ #endif
86848700 #ifdef WOLFSSL_HEAP_TEST
86858701 }
86868702 #endif
0 commit comments