From 3457c2e2fd91fd5a4501a04ba82199535d541903 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 23 Nov 2024 16:13:32 +0000 Subject: [PATCH] Zephyr: Track memory allocations --- examples/zephyr/Makefile | 10 +++++++--- examples/zephyr/client-src/src/main.c | 2 +- src/coap_mbedtls.c | 2 ++ zephyr/CMakeLists.txt | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/zephyr/Makefile b/examples/zephyr/Makefile index fac278bb..3e4776b0 100644 --- a/examples/zephyr/Makefile +++ b/examples/zephyr/Makefile @@ -3,7 +3,7 @@ ZEPHYR_PROJECT?=~/zephyrproject all: coap-client coap-client: client-src/src/main.c client-src/* - LIBCOAP_DIR=`pwd`/../.. ;\ + @LIBCOAP_DIR=`pwd`/../.. ;\ (. $(ZEPHYR_PROJECT)/.venv/bin/activate ;\ cd $(ZEPHYR_PROJECT)/zephyr ;\ west build -p always -b native_sim \ @@ -12,5 +12,9 @@ coap-client: client-src/src/main.c client-src/* -DEXTRA_ZEPHYR_MODULES=$${LIBCOAP_DIR} \ -DEXTRA_CONF_FILE=$${LIBCOAP_DIR}/zephyr/libcoap-mbedtls.conf \ --fresh ;\ - deactivate) ;\ - cp -f $(ZEPHYR_PROJECT)/zephyr/build/zephyr/zephyr.exe coap-client + deactivate) + @cp -f $(ZEPHYR_PROJECT)/zephyr/build/zephyr/zephyr.exe coap-client + +clean: + @rm -rf $(ZEPHYR_PROJECT)/zephyr/build + @rm -f coap-client diff --git a/examples/zephyr/client-src/src/main.c b/examples/zephyr/client-src/src/main.c index 8a7685d6..9be310cb 100644 --- a/examples/zephyr/client-src/src/main.c +++ b/examples/zephyr/client-src/src/main.c @@ -208,5 +208,5 @@ fail: coap_free_context(coap_context); coap_cleanup(); - return 0; + exit(0); } diff --git a/src/coap_mbedtls.c b/src/coap_mbedtls.c index 0106b71e..c1540675 100644 --- a/src/coap_mbedtls.c +++ b/src/coap_mbedtls.c @@ -84,6 +84,8 @@ #define mbedtls_realloc(a,b) realloc(a,b) #define mbedtls_strdup(a) strdup(a) #define mbedtls_strndup(a,b) strndup(a,b) +#undef mbedtls_free +#define mbedtls_free(a) free(a) #ifndef MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED /* definition changed in later mbedtls code versions */ diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index e7c4cb93..f40050df 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -106,6 +106,7 @@ if(CONFIG_LIBCOAP) add_subdirectory(.. build) target_compile_definitions(coap-3 PUBLIC WITH_ZEPHYR) + target_compile_definitions(coap-3 PUBLIC COAP_MEMORY_TYPE_TRACK=1) target_link_libraries(coap-3 PUBLIC zephyr_interface) set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS coap-3)