From ba6ea2fd0c0559c6e8d8108bd25252ef7aab68d0 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 24 Aug 2017 22:52:37 +0200 Subject: fixed memory leaks and memory measurement leaks by removing -fsized-deallocation * Array allocations were not properly accounted since the compiler would call the replacement new() which assumes that it would always be called along with the replacement sized-deletion. This is not true for array new[] allocations resulting in a constant increase of memory_usage and unrecoverable situations. This problem however could be fixed in principle by avoiding memory counting for arrays or falling back to malloc_usable_size. * The bigger problem was that some STLs (new_allocator) are broken, calling the non-sized delete for regular new() calls which could in principle be matched by sized-delete. This is also the reason why I had to provide a non-sized delete replacement, which in reality intoduced memory leaks. * Since adding checks for the broken compiler versions or a configure-time check that tries to detect these broken systems seems tedious, I simply removed that optimization. * This means we always have to rely on malloc_usable_size() now for non-SciTECO-object memory measurement. * Perhaps in the future, there should be an option for allowing portable measurement at the cost of memory usage, by prefixing each memory chunk with the chunk size. Maintainers could then decide to optimize their build for "speed" at the cost of memory overhead. * Another solution to this non-ending odyssey might be to introduce our own allocator, replacing malloc(), and allowing our own precise measurements. --- configure.ac | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index c341183..032ab10 100644 --- a/configure.ac +++ b/configure.ac @@ -181,29 +181,6 @@ esac AC_CHECK_HEADERS([malloc.h malloc_np.h]) AC_CHECK_FUNCS([malloc_trim malloc_usable_size]) -# Check whether compiler supports global sized deallocations. -# If yes, this will improve the memory limiting fallback -# implementation. -# Once we can depend on C++14, this check is no longer necessary. -AC_CACHE_CHECK([if C++ compiler supports -fsized-deallocation], - [sciteco_cv_sized_deallocation_result], [ - AC_LANG_PUSH(C++) - OLD_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -fsized-deallocation" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM( - [[#include ]], - [[(::operator delete)(0, 256)]] - )], sciteco_cv_sized_deallocation_result=yes, - sciteco_cv_sized_deallocation_result=no) - CXXFLAGS="$OLD_CXXFLAGS" - AC_LANG_POP(C++) -]) -if [[ x$sciteco_cv_sized_deallocation_result = xyes ]]; then - AC_DEFINE(HAVE_SIZED_DEALLOCATION, 1, - [C++ compiler supports -fsized-deallocation]) - CXXFLAGS="$CXXFLAGS -fsized-deallocation" -fi - # # Config options # -- cgit v1.2.3