Skip to content

Commit 3cc7bbe

Browse files
authored
Merge pull request wolfSSL#7737 from JacobBarthelmeh/staticmemory-singlethreaded
fix for staticmemory and singlethreaded build
2 parents 0979fe8 + 6703a58 commit 3cc7bbe

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/internal.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,7 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
27742774
#ifdef WOLFSSL_STATIC_MEMORY
27752775
static 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

wolfcrypt/src/memory.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,13 @@ int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
793793
void wc_UnloadStaticMemory(WOLFSSL_HEAP_HINT* heap)
794794
{
795795
WOLFSSL_ENTER("wc_UnloadStaticMemory");
796+
#ifndef SINGLE_THREADED
796797
if (heap != NULL && heap->memory != NULL) {
797798
wc_FreeMutex(&heap->memory->memory_mutex);
798799
}
800+
#else
801+
(void)heap;
802+
#endif
799803
}
800804

801805
#ifndef WOLFSSL_STATIC_MEMORY_LEAN

0 commit comments

Comments
 (0)