diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,11 @@ message(FATAL_ERROR "You are missing some Linux headers required to compile heaptrack.") endif() +# cfree() does not exist in glibc 2.26+. +# See: https://bugs.kde.org/show_bug.cgi?id=383889 +include(CheckSymbolExists) +check_symbol_exists(cfree malloc.h HAVE_CFREE) + set(BIN_INSTALL_DIR "bin") set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)") set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}") diff --git a/src/track/heaptrack_inject.cpp b/src/track/heaptrack_inject.cpp --- a/src/track/heaptrack_inject.cpp +++ b/src/track/heaptrack_inject.cpp @@ -17,6 +17,7 @@ */ #include "libheaptrack.h" +#include "util/config.h" #include #include @@ -42,12 +43,6 @@ #error unsupported word size #endif -#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(__USE_MISC) -#define HAVE_CFREE 1 -#else -#define HAVE_CFREE 0 -#endif - namespace { namespace Elf { diff --git a/src/track/heaptrack_preload.cpp b/src/track/heaptrack_preload.cpp --- a/src/track/heaptrack_preload.cpp +++ b/src/track/heaptrack_preload.cpp @@ -17,6 +17,7 @@ */ #include "libheaptrack.h" +#include "util/config.h" #include #include @@ -33,11 +34,6 @@ #else # define HAVE_ALIGNED_ALLOC 0 #endif -#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(__USE_MISC) -# define HAVE_CFREE 1 -#else -# define HAVE_CFREE 0 -#endif extern "C" { __attribute__((weak)) void __libc_freeres(); diff --git a/src/util/config.h.cmake b/src/util/config.h.cmake --- a/src/util/config.h.cmake +++ b/src/util/config.h.cmake @@ -29,4 +29,8 @@ #define HEAPTRACK_DEBUG_BUILD @HEAPTRACK_DEBUG_BUILD@ +// cfree() does not exist in glibc 2.26+. +// See: https://bugs.kde.org/show_bug.cgi?id=383889 +#cmakedefine01 HAVE_CFREE + #endif // HEAPTRACK_CONFIG_H diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt --- a/tests/manual/CMakeLists.txt +++ b/tests/manual/CMakeLists.txt @@ -2,6 +2,10 @@ add_executable(test_c test.c) add_executable(test_cpp test.cpp) +set_target_properties(test_cpp PROPERTIES + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/../../src/ +) + add_executable(threaded threaded.cpp) target_link_libraries(threaded ${CMAKE_THREAD_LIBS_INIT}) diff --git a/tests/manual/test.cpp b/tests/manual/test.cpp --- a/tests/manual/test.cpp +++ b/tests/manual/test.cpp @@ -19,6 +19,8 @@ #include #include +#include "util/config.h" + #if defined(_ISOC11_SOURCE) # define HAVE_ALIGNED_ALLOC 1 #else @@ -82,7 +84,11 @@ buf = calloc(5, 5); printf("calloc: %p\n", buf); +#if HAVE_CFREE cfree(buf); +#else + free(buf); +#endif #if HAVE_ALIGNED_ALLOC buf = aligned_alloc(16, 160);