diff --git a/configure.ac b/configure.ac index 053a763e94..c0d9e4b6ea 100644 --- a/configure.ac +++ b/configure.ac @@ -8077,6 +8077,10 @@ do ENABLED_STATICMEMORY=yes AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_LEAN_STATIC_MEMORY" ;; + debug) + ENABLED_STATICMEMORY=yes + AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_DEBUG_MEMORY_CALLBACK" + ;; *) AC_MSG_ERROR([Invalid choice for staticmemory.]) break;; diff --git a/examples/client/client.c b/examples/client/client.c index 4a2f773d9e..d84f6938e5 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -1865,6 +1865,38 @@ static int client_srtp_test(WOLFSSL *ssl, func_args *args) } #endif /* WOLFSSL_SRTP */ +#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK +static void ExampleDebugMemoryCb(size_t sz, int bucketSz, byte st, int type) { + switch (st) { + case WOLFSSL_DEBUG_MEMORY_ALLOC: + if (type == DYNAMIC_TYPE_IN_BUFFER) { + printf("IN BUFFER: "); + } + + if (type == DYNAMIC_TYPE_OUT_BUFFER) { + printf("OUT BUFFER: "); + } + + printf("Alloc'd %d bytes using bucket size %d\n", (int)sz, + bucketSz); + break; + + case WOLFSSL_DEBUG_MEMORY_FAIL: + printf("Failed when trying to allocate %d bytes\n", (int)sz); + break; + + case WOLFSSL_DEBUG_MEMORY_FREE: + printf("Free'ing : %d\n", (int)sz); + break; + + case WOLFSSL_DEBUG_MEMORY_INIT: + printf("Creating memory bucket of size : %d\n", bucketSz); + break; + } +} +#endif + + THREAD_RETURN WOLFSSL_THREAD client_test(void* args) { @@ -3045,6 +3077,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args) err_sys("unable to load static memory"); } +#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK + wolfSSL_SetDebugMemoryCb(ExampleDebugMemoryCb); +#endif ctx = wolfSSL_CTX_new_ex(method(heap), heap); if (ctx == NULL) err_sys("unable to get ctx"); diff --git a/wolfcrypt/src/memory.c b/wolfcrypt/src/memory.c index b478376327..6efd1a1bb3 100644 --- a/wolfcrypt/src/memory.c +++ b/wolfcrypt/src/memory.c @@ -531,9 +531,9 @@ static DebugMemoryCb DebugCb = NULL; /* Used to set a debug memory callback. Helpful in cases where * printf is not available. */ -void wolfSSL_SetDebugCallback(DebugMemoryCb in) +void wolfSSL_SetDebugMemoryCb(DebugMemoryCb cb) { - DebugCb = in; + DebugCb = cb; } #endif