mirror of https://github.com/wolfSSL/wolfssl.git
Merge pull request #8180 from JacobBarthelmeh/staticmemory
wc_UnloadStaticMemory should be used to free mutexpull/8189/head
commit
c06b5fadc1
|
@ -2769,25 +2769,6 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
|
||||||
(void)heapAtCTXInit;
|
(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)
|
void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
|
||||||
{
|
{
|
||||||
|
@ -2809,9 +2790,6 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
|
||||||
if (ctx->err == WC_NO_ERR_TRACE(CTX_INIT_MUTEX_E)) {
|
if (ctx->err == WC_NO_ERR_TRACE(CTX_INIT_MUTEX_E)) {
|
||||||
SSL_CtxResourceFree(ctx);
|
SSL_CtxResourceFree(ctx);
|
||||||
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
|
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
|
||||||
#ifdef WOLFSSL_STATIC_MEMORY
|
|
||||||
SSL_CtxResourceFreeStaticMem(heap);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2829,9 +2807,6 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
|
||||||
#endif
|
#endif
|
||||||
wolfSSL_RefFree(&ctx->ref);
|
wolfSSL_RefFree(&ctx->ref);
|
||||||
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
|
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
|
||||||
#ifdef WOLFSSL_STATIC_MEMORY
|
|
||||||
SSL_CtxResourceFreeStaticMem(heap);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
WOLFSSL_MSG("CTX ref count not 0 yet, no free");
|
WOLFSSL_MSG("CTX ref count not 0 yet, no free");
|
||||||
|
|
42
tests/api.c
42
tests/api.c
|
@ -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
|
| Platform dependent function test
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
@ -99661,6 +99702,7 @@ TEST_CASE testCases[] = {
|
||||||
TEST_DECL(test_wolfCrypt_Init),
|
TEST_DECL(test_wolfCrypt_Init),
|
||||||
|
|
||||||
TEST_DECL(test_wc_LoadStaticMemory_ex),
|
TEST_DECL(test_wc_LoadStaticMemory_ex),
|
||||||
|
TEST_DECL(test_wc_LoadStaticMemory_CTX),
|
||||||
|
|
||||||
/* Locking with Compat Mutex */
|
/* Locking with Compat Mutex */
|
||||||
TEST_DECL(test_wc_SetMutexCb),
|
TEST_DECL(test_wc_SetMutexCb),
|
||||||
|
|
Loading…
Reference in New Issue