Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wc_UnloadStaticMemory should be used to free mutex #8180

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2769,25 +2769,6 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
(void)heapAtCTXInit;
}

#ifdef WOLFSSL_STATIC_MEMORY
static void SSL_CtxResourceFreeStaticMem(void* heap)
{
#ifndef SINGLE_THREADED
if (heap != NULL
#ifdef WOLFSSL_HEAP_TEST
/* avoid dereferencing a test value */
&& heap != (void*)WOLFSSL_HEAP_TEST
#endif
) {
WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap;
WOLFSSL_HEAP* mem = hint->memory;
wc_FreeMutex(&mem->memory_mutex);
}
#else
(void)heap;
#endif
}
#endif /* WOLFSSL_STATIC_MEMORY */

void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
{
Expand All @@ -2809,9 +2790,6 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
if (ctx->err == WC_NO_ERR_TRACE(CTX_INIT_MUTEX_E)) {
SSL_CtxResourceFree(ctx);
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
#ifdef WOLFSSL_STATIC_MEMORY
SSL_CtxResourceFreeStaticMem(heap);
#endif
}
return;
}
Expand All @@ -2829,9 +2807,6 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
#endif
wolfSSL_RefFree(&ctx->ref);
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
#ifdef WOLFSSL_STATIC_MEMORY
SSL_CtxResourceFreeStaticMem(heap);
#endif
}
else {
WOLFSSL_MSG("CTX ref count not 0 yet, no free");
Expand Down
42 changes: 42 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,47 @@ static int test_wc_LoadStaticMemory_ex(void)
}


static int test_wc_LoadStaticMemory_CTX(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_STATIC_MEMORY) && !defined(NO_WOLFSSL_CLIENT)
byte staticMemory[TEST_LSM_STATIC_SIZE];
word32 sizeList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_BUCKETS };
word32 distList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_DIST };
WOLFSSL_HEAP_HINT* heap;
WOLFSSL_CTX *ctx1 = NULL, *ctx2 = NULL;


/* Set the size of the static buffer to exactly the minimum size. */
heap = NULL;
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
WOLFMEM_DEF_BUCKETS, sizeList, distList,
staticMemory, sizeof(staticMemory), 0, 1),
0);

/* Creating two WOLFSSL_CTX objects from the same heap hint and free'ing
* them should not cause issues. */
ExpectNotNull((ctx1 = wolfSSL_CTX_new_ex(wolfSSLv23_client_method_ex(heap),
heap)));
wolfSSL_CTX_free(ctx1);
ExpectNotNull((ctx2 = wolfSSL_CTX_new_ex(wolfSSLv23_client_method_ex(heap),
heap)));
wolfSSL_CTX_free(ctx2);

/* two CTX's at once */
ExpectNotNull((ctx1 = wolfSSL_CTX_new_ex(wolfSSLv23_client_method_ex(heap),
heap)));
ExpectNotNull((ctx2 = wolfSSL_CTX_new_ex(wolfSSLv23_client_method_ex(heap),
heap)));
wolfSSL_CTX_free(ctx1);
wolfSSL_CTX_free(ctx2);

wc_UnloadStaticMemory(heap);
#endif /* WOLFSSL_STATIC_MEMORY */
return EXPECT_RESULT();
}


/*----------------------------------------------------------------------------*
| Platform dependent function test
*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -97395,6 +97436,7 @@ TEST_CASE testCases[] = {
TEST_DECL(test_wolfCrypt_Init),

TEST_DECL(test_wc_LoadStaticMemory_ex),
TEST_DECL(test_wc_LoadStaticMemory_CTX),

/* Locking with Compat Mutex */
TEST_DECL(test_wc_SetMutexCb),
Expand Down
Loading