Skip to content

Commit 6be5526

Browse files
committed
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.
1 parent f6ae432 commit 6be5526

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

tests/api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ static int test_wc_LoadStaticMemory_ex(void)
744744
(word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
745745
0, 1),
746746
0);
747+
wc_UnloadStaticMemory(heap);
747748

748749
/* Success case. */
749750
heap = NULL;
@@ -752,6 +753,7 @@ static int test_wc_LoadStaticMemory_ex(void)
752753
staticMemory, (word32)sizeof(staticMemory),
753754
0, 1),
754755
0);
756+
wc_UnloadStaticMemory(heap);
755757
#endif /* WOLFSSL_STATIC_MEMORY */
756758
return EXPECT_RESULT();
757759
}

wolfcrypt/src/memory.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,15 @@ int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
729729
}
730730

731731

732+
void wc_UnloadStaticMemory(WOLFSSL_HEAP_HINT* heap)
733+
{
734+
WOLFSSL_ENTER("wc_UnloadStaticMemory");
735+
if (heap != NULL && heap->memory != NULL) {
736+
wc_FreeMutex(&heap->memory->memory_mutex);
737+
}
738+
}
739+
740+
732741
/* returns the size of management memory needed for each bucket.
733742
* This is memory that is used to keep track of and align memory buckets. */
734743
int wolfSSL_MemoryPaddingSz(void)

wolfssl/wolfcrypt/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
222222
int flag, int max);
223223
WOLFSSL_API int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
224224
unsigned char* buf, unsigned int sz, int flag, int max);
225+
WOLFSSL_API void wc_UnloadStaticMemory(WOLFSSL_HEAP_HINT* heap);
225226

226227
WOLFSSL_API int wolfSSL_GetMemStats(WOLFSSL_HEAP* heap,
227228
WOLFSSL_MEM_STATS* stats);

0 commit comments

Comments
 (0)