mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 02:37:28 +02:00
Added new API wolfSSL_ResetAllocators
to allow reset of memory callbacks to defaults. Added new CleanupMemoryTracker
which restores memory callback functions. This resolves issue with trying to free memory allocated prior to InitMemoryTracker.
This commit is contained in:
@ -46,9 +46,9 @@
|
||||
|
||||
|
||||
/* Set these to default values initially. */
|
||||
static wolfSSL_Malloc_cb malloc_function = 0;
|
||||
static wolfSSL_Free_cb free_function = 0;
|
||||
static wolfSSL_Realloc_cb realloc_function = 0;
|
||||
static wolfSSL_Malloc_cb malloc_function = NULL;
|
||||
static wolfSSL_Free_cb free_function = NULL;
|
||||
static wolfSSL_Realloc_cb realloc_function = NULL;
|
||||
|
||||
int wolfSSL_SetAllocators(wolfSSL_Malloc_cb mf,
|
||||
wolfSSL_Free_cb ff,
|
||||
@ -74,6 +74,16 @@ int wolfSSL_SetAllocators(wolfSSL_Malloc_cb mf,
|
||||
return res;
|
||||
}
|
||||
|
||||
int wolfSSL_ResetAllocators(void)
|
||||
{
|
||||
/* allow nulls to be set for callbacks to restore defaults */
|
||||
malloc_function = NULL;
|
||||
free_function = NULL;
|
||||
realloc_function = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_GetAllocators(wolfSSL_Malloc_cb* mf,
|
||||
wolfSSL_Free_cb* ff,
|
||||
wolfSSL_Realloc_cb* rf)
|
||||
|
@ -237,6 +237,12 @@
|
||||
(unsigned long)ourMemStats.currentBytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC WC_INLINE int CleanupMemoryTracker(void)
|
||||
{
|
||||
/* restore default allocators */
|
||||
return wolfSSL_ResetAllocators();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USE_WOLFSSL_MEMORY */
|
||||
|
@ -77,7 +77,7 @@
|
||||
WOLFSSL_API int wolfSSL_SetAllocators(wolfSSL_Malloc_cb,
|
||||
wolfSSL_Free_cb,
|
||||
wolfSSL_Realloc_cb);
|
||||
|
||||
WOLFSSL_API int wolfSSL_ResetAllocators(void);
|
||||
WOLFSSL_API int wolfSSL_GetAllocators(wolfSSL_Malloc_cb*,
|
||||
wolfSSL_Free_cb*,
|
||||
wolfSSL_Realloc_cb*);
|
||||
|
Reference in New Issue
Block a user