Generic Memory Pools

1. Add API for function `wc_UnloadStaticMemory()` which frees the mutex
   used by the static memory pool.
2. Update the `wc_LoadStaticMemory_ex()` test to free the static memory
   pool's mutex on each successful test case.
This commit is contained in:
John Safranek
2024-04-29 22:22:08 -07:00
parent f6ae432be1
commit 6be55269db
3 changed files with 12 additions and 0 deletions

View File

@ -744,6 +744,7 @@ static int test_wc_LoadStaticMemory_ex(void)
(word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
0, 1),
0);
wc_UnloadStaticMemory(heap);
/* Success case. */
heap = NULL;
@ -752,6 +753,7 @@ static int test_wc_LoadStaticMemory_ex(void)
staticMemory, (word32)sizeof(staticMemory),
0, 1),
0);
wc_UnloadStaticMemory(heap);
#endif /* WOLFSSL_STATIC_MEMORY */
return EXPECT_RESULT();
}

View File

@ -729,6 +729,15 @@ int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
}
void wc_UnloadStaticMemory(WOLFSSL_HEAP_HINT* heap)
{
WOLFSSL_ENTER("wc_UnloadStaticMemory");
if (heap != NULL && heap->memory != NULL) {
wc_FreeMutex(&heap->memory->memory_mutex);
}
}
/* returns the size of management memory needed for each bucket.
* This is memory that is used to keep track of and align memory buckets. */
int wolfSSL_MemoryPaddingSz(void)

View File

@ -222,6 +222,7 @@ WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
int flag, int max);
WOLFSSL_API int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
unsigned char* buf, unsigned int sz, int flag, int max);
WOLFSSL_API void wc_UnloadStaticMemory(WOLFSSL_HEAP_HINT* heap);
WOLFSSL_API int wolfSSL_GetMemStats(WOLFSSL_HEAP* heap,
WOLFSSL_MEM_STATS* stats);