Skip to content

Commit

Permalink
tie in static memory debug callback
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed May 29, 2024
1 parent 288fe43 commit 6cca3a0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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;;
Expand Down
35 changes: 35 additions & 0 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6cca3a0

Please sign in to comment.