Moved mem_track.h into wolfssl/wolfcrypt. Added new WOLFSSL_DEBUG_MEMORY option. Added documentation for using mem_track and new debug memory option.

This commit is contained in:
David Garske
2016-05-04 10:04:38 -07:00
parent ab53d732ce
commit 822d71431e
9 changed files with 134 additions and 26 deletions

View File

@@ -130,7 +130,7 @@
#include "wolfcrypt/benchmark/benchmark.h"
#ifdef USE_WOLFSSL_MEMORY
#include "wolfssl/mem_track.h"
#include "wolfssl/wolfcrypt/mem_track.h"
#endif
void bench_des(void);

View File

@@ -43,6 +43,7 @@
#include <stdio.h>
#endif
/* Set these to default values initially. */
static wolfSSL_Malloc_cb malloc_function = 0;
static wolfSSL_Free_cb free_function = 0;
@@ -72,15 +73,24 @@ int wolfSSL_SetAllocators(wolfSSL_Malloc_cb mf,
return res;
}
#ifdef WOLFSSL_DEBUG_MEMORY
void* wolfSSL_Malloc(size_t size, const char* func, unsigned int line)
#else
void* wolfSSL_Malloc(size_t size)
#endif
{
void* res = 0;
if (malloc_function)
if (malloc_function) {
#ifdef WOLFSSL_DEBUG_MEMORY
res = malloc_function(size, func, line);
#else
res = malloc_function(size);
else
#endif
}
else {
res = malloc(size);
}
#ifdef WOLFSSL_MALLOC_CHECK
if (res == NULL)
@@ -90,22 +100,42 @@ void* wolfSSL_Malloc(size_t size)
return res;
}
#ifdef WOLFSSL_DEBUG_MEMORY
void wolfSSL_Free(void *ptr, const char* func, unsigned int line)
#else
void wolfSSL_Free(void *ptr)
#endif
{
if (free_function)
if (free_function) {
#ifdef WOLFSSL_DEBUG_MEMORY
free_function(ptr, func, line);
#else
free_function(ptr);
else
#endif
}
else {
free(ptr);
}
}
#ifdef WOLFSSL_DEBUG_MEMORY
void* wolfSSL_Realloc(void *ptr, size_t size, const char* func, unsigned int line)
#else
void* wolfSSL_Realloc(void *ptr, size_t size)
#endif
{
void* res = 0;
if (realloc_function)
if (realloc_function) {
#ifdef WOLFSSL_DEBUG_MEMORY
res = realloc_function(ptr, size, func, line);
#else
res = realloc_function(ptr, size);
else
#endif
}
else {
res = realloc(ptr, size);
}
return res;
}

View File

@@ -143,7 +143,7 @@
#include "wolfcrypt/test/test.h"
#ifdef USE_WOLFSSL_MEMORY
#include "wolfssl/mem_track.h"
#include "wolfssl/wolfcrypt/mem_track.h"
#endif