CppUTest and AddressSanitizer (ASAN) both instrument memory allocation functions (malloc, free, new, delete). When used together without proper configuration, they can conflict:
malloc/free to track allocationsMemoryLeakDetectorNewMacros.h)malloc/free at compile timeWe've configured the build system to disable CppUTest's memory leak detection when ASAN is enabled:
1. CMakeLists.txt (tests/)
if(ENABLE_ADDRESS_SANITIZER OR ENABLE_UNDEFINED_SANITIZER)
add_compile_definitions(CPPUTEST_MEMORY_LEAK_DETECTION_DISABLED)
message(STATUS "CppUTest memory leak detection disabled (using AddressSanitizer instead)")
endif()
This tells CppUTest to use standard C/C++ library functions without wrapping them.
2. security_tests.cpp
#ifdef CPPUTEST_MEMORY_LEAK_DETECTION_DISABLED
#define CPPUTEST_USE_STD_CPP_LIB
#define CPPUTEST_USE_STD_C_LIB
#endif
These macros instruct CppUTest to use the standard library instead of its custom memory wrappers.
cd bin/posix
cmake .
make -j$(nproc)
./tests/OpENer_Tests -g NetworkHandlerSecurity
cd bin/posix
cmake -DENABLE_ADDRESS_SANITIZER=ON .
make -j$(nproc)
ASAN_OPTIONS="verbosity=0" ./tests/OpENer_Tests -g NetworkHandlerSecurity
| Feature | CppUTest | ASAN | Both |
|---|---|---|---|
| Leak detection | ✓ | ✓ | ASAN only |
| Buffer overflow | - | ✓ | ✓ |
| Use-after-free | - | ✓ | ✓ |
| Double-free | - | ✓ | ✓ |
| Integer overflow | - | ✓ (UBSAN) | ✓ |
| Stack issues | - | ✓ | ✓ |
| Uninitialized reads | - | Limited | Limited |
Recommendation: Use ASAN for comprehensive memory safety testing.
To verify there are no conflicts:
# Build with ASAN
cd bin/posix && cmake -DENABLE_ADDRESS_SANITIZER=ON . && make -j$(nproc)
# Run tests - should see no conflicts
ASAN_OPTIONS="verbosity=0" ./tests/OpENer_Tests -g NetworkHandlerSecurity
# Check for ASAN errors (exit code 1 = error found)
echo "Exit code: $?"
CHECK_EQUAL_TEXT, CHECK_EQUAL_NOCASE_TEXT for memory checksStatus: ✅ CppUTest and ASAN are now compatible and won't conflict