mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-01-27 02:52:19 +01:00
wolfssl/wolfcrypt/mem_track.h and wolfcrypt/src/memory.c: add WOLFSSL_API extern memoryStats *wc_MemStats_Ptr, set by InitMemoryTracker() and cleared by CleanupMemoryTracker(), allowing public access to the memory statistics.
tests/unit.c: at end of unit_test(), when WOLFSSL_TRACK_MEMORY, explicitly wolfSSL_Cleanup() then check and error if wc_MemStats_Ptr->currentBytes > 0.
This commit is contained in:
11
tests/unit.c
11
tests/unit.c
@@ -324,6 +324,17 @@ exit:
|
||||
err_sys("Failed to free netRandom context");
|
||||
#endif /* HAVE_WNR */
|
||||
|
||||
#ifdef WOLFSSL_TRACK_MEMORY
|
||||
if (ret == 0) {
|
||||
(void)wolfSSL_Cleanup();
|
||||
if (wc_MemStats_Ptr->currentBytes > 0)
|
||||
{
|
||||
fprintf(stderr, "WOLFSSL_TRACK_MEMORY: currentBytes after cleanup is %ld\n", wc_MemStats_Ptr->currentBytes);
|
||||
ret = MEMORY_E;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ret == 0) {
|
||||
puts("\nunit_test: Success for all configured tests.");
|
||||
fflush(stdout);
|
||||
|
||||
@@ -521,6 +521,11 @@ void* wolfSSL_Realloc(void *ptr, size_t size)
|
||||
}
|
||||
#endif /* WOLFSSL_STATIC_MEMORY */
|
||||
|
||||
#ifdef WOLFSSL_TRACK_MEMORY
|
||||
#include <wolfssl/wolfcrypt/mem_track.h>
|
||||
WOLFSSL_API memoryStats *wc_MemStats_Ptr;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_STATIC_MEMORY
|
||||
|
||||
struct wc_Memory {
|
||||
|
||||
@@ -133,6 +133,7 @@ typedef struct memoryList {
|
||||
|
||||
|
||||
static memoryStats ourMemStats;
|
||||
WOLFSSL_API extern memoryStats *wc_MemStats_Ptr;
|
||||
|
||||
#ifdef DO_MEM_LIST
|
||||
#include <pthread.h>
|
||||
@@ -384,6 +385,8 @@ static WC_INLINE int InitMemoryTracker(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
wc_MemStats_Ptr = &ourMemStats;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -427,6 +430,7 @@ static WC_INLINE void ShowMemoryTracker(void)
|
||||
|
||||
static WC_INLINE int CleanupMemoryTracker(void)
|
||||
{
|
||||
wc_MemStats_Ptr = NULL;
|
||||
/* restore default allocators */
|
||||
return wolfSSL_SetAllocators(mfDefault, ffDefault, rfDefault);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user