Skip to content

Commit 6cca3a0

Browse files
tie in static memory debug callback
1 parent 288fe43 commit 6cca3a0

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8077,6 +8077,10 @@ do
80778077
ENABLED_STATICMEMORY=yes
80788078
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_LEAN_STATIC_MEMORY"
80798079
;;
8080+
debug)
8081+
ENABLED_STATICMEMORY=yes
8082+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_DEBUG_MEMORY_CALLBACK"
8083+
;;
80808084
*)
80818085
AC_MSG_ERROR([Invalid choice for staticmemory.])
80828086
break;;

examples/client/client.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,38 @@ static int client_srtp_test(WOLFSSL *ssl, func_args *args)
18651865
}
18661866
#endif /* WOLFSSL_SRTP */
18671867

1868+
#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
1869+
static void ExampleDebugMemoryCb(size_t sz, int bucketSz, byte st, int type) {
1870+
switch (st) {
1871+
case WOLFSSL_DEBUG_MEMORY_ALLOC:
1872+
if (type == DYNAMIC_TYPE_IN_BUFFER) {
1873+
printf("IN BUFFER: ");
1874+
}
1875+
1876+
if (type == DYNAMIC_TYPE_OUT_BUFFER) {
1877+
printf("OUT BUFFER: ");
1878+
}
1879+
1880+
printf("Alloc'd %d bytes using bucket size %d\n", (int)sz,
1881+
bucketSz);
1882+
break;
1883+
1884+
case WOLFSSL_DEBUG_MEMORY_FAIL:
1885+
printf("Failed when trying to allocate %d bytes\n", (int)sz);
1886+
break;
1887+
1888+
case WOLFSSL_DEBUG_MEMORY_FREE:
1889+
printf("Free'ing : %d\n", (int)sz);
1890+
break;
1891+
1892+
case WOLFSSL_DEBUG_MEMORY_INIT:
1893+
printf("Creating memory bucket of size : %d\n", bucketSz);
1894+
break;
1895+
}
1896+
}
1897+
#endif
1898+
1899+
18681900

18691901
THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
18701902
{
@@ -3045,6 +3077,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
30453077
err_sys("unable to load static memory");
30463078
}
30473079

3080+
#ifdef WOLFSSL_DEBUG_MEMORY_CALLBACK
3081+
wolfSSL_SetDebugMemoryCb(ExampleDebugMemoryCb);
3082+
#endif
30483083
ctx = wolfSSL_CTX_new_ex(method(heap), heap);
30493084
if (ctx == NULL)
30503085
err_sys("unable to get ctx");

wolfcrypt/src/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ static DebugMemoryCb DebugCb = NULL;
531531

532532
/* Used to set a debug memory callback. Helpful in cases where
533533
* printf is not available. */
534-
void wolfSSL_SetDebugCallback(DebugMemoryCb in)
534+
void wolfSSL_SetDebugMemoryCb(DebugMemoryCb cb)
535535
{
536-
DebugCb = in;
536+
DebugCb = cb;
537537
}
538538
#endif
539539

0 commit comments

Comments
 (0)