From 5e089f01d6a82db479bbfceffab1eab63c39a455 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 26 Dec 2007 05:02:55 +0000 Subject: [PATCH] memdebug fixes --- Jamfile | 2 +- src/memdebug.cpp | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Jamfile b/Jamfile index 70a3896ee..dedd5bd7d 100755 --- a/Jamfile +++ b/Jamfile @@ -153,7 +153,7 @@ rule building ( properties * ) feature disk-stats : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_DISK_STATS ; -feature memdebug : off on : ; +feature memdebug : off on : propagated ; feature logging : none default verbose : composite propagated link-incompatible ; feature.compose default : TORRENT_LOGGING ; diff --git a/src/memdebug.cpp b/src/memdebug.cpp index a80d2d4c6..c31ec30f8 100644 --- a/src/memdebug.cpp +++ b/src/memdebug.cpp @@ -36,6 +36,11 @@ POSSIBILITY OF SUCH DAMAGE. // Prototypes for __malloc_hook, __free_hook #include #include +#include +#include +#include +#include +#include namespace { @@ -50,7 +55,7 @@ namespace { allocation_point_t(): allocated(0) {} int index; - size_type allocated; + boost::int64_t allocated; }; typedef boost::array stacktrace_t; @@ -63,6 +68,8 @@ namespace void* (*old_malloc_hook)(size_t, const void *); void (*old_free_hook)(void*, const void *); + void my_free_hook(void *ptr, const void *caller); + void* my_malloc_hook(size_t size, const void *caller) { void *result; @@ -79,17 +86,17 @@ namespace int stacksize = backtrace(&stack[0], 10); allocation_map_t::iterator i = allocation_points.lower_bound(stack); - if (i == allocation_points.end() || i.first != stack) + if (i == allocation_points.end() || i->first != stack) { i = allocation_points.insert(i, std::make_pair(stack, allocation_point_t())); i->second.index = allocation_point_index++; i->second.allocated = size; - memory_index_log << "#" << i->second.index << " "; - char** symbols = backtrace_symbols(stack, stacksize); + malloc_index_log << "#" << i->second.index << " "; + char** symbols = backtrace_symbols(&stack[0], stacksize); for (int j = 0; j < stacksize; ++j) - memory_index_log << symbols[j] << " "; - memory_index_log << std::endl; + malloc_index_log << symbols[j] << " "; + malloc_index_log << std::endl; } else {