From 47cd9b3030b2cda212209dd9e282274d0d7547f0 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Mon, 1 Aug 2016 19:12:26 +0200 Subject: MemoryUsage: fix GetTotalMallocUsage The mallinfo() interface is ill-designed. It returns 'int' as occupied memory. This means at most 2G. This causes troubles when capping the memory to 3G by -max-memory=3000 for example. We cannot fix the interface, but we can at least extend the space to 4G. So cast those 'int's to 'unsigned int's to avoid sign extension. Then do the addition on 'size_t' to count on 64bit values (on 64 bit). Apart from that, the original 'int' + 'int' led to overflow which is undefined on 'signed int's in C. Also, when klee is run under valgrind, generic.current_allocated_bytes from gperftools does not touch the passed pointer and in that case, we return garbage from GetTotalMallocUsage. So initialize 'value' to 0 to avoid the problem. And since GetNumericProperty accepts 'size_t', let's define 'value' as such. It was 'uint64_t' previously and they differ on 32 bit. Signed-off-by: Jiri Slaby --- lib/Support/MemoryUsage.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/Support/MemoryUsage.cpp') diff --git a/lib/Support/MemoryUsage.cpp b/lib/Support/MemoryUsage.cpp index a9f4026d..d141593a 100644 --- a/lib/Support/MemoryUsage.cpp +++ b/lib/Support/MemoryUsage.cpp @@ -26,7 +26,7 @@ using namespace klee; size_t util::GetTotalMallocUsage() { #ifdef HAVE_GPERFTOOLS_MALLOC_EXTENSION_H - uint64_t value; + size_t value = 0; MallocExtension::instance()->GetNumericProperty( "generic.current_allocated_bytes", &value); return value; @@ -36,9 +36,9 @@ size_t util::GetTotalMallocUsage() { // does not include mmap()'ed memory in mi.uordblks // but other implementations (e.g. tcmalloc) do. #if defined(__GLIBC__) - return mi.uordblks + mi.hblkhd; + return (size_t)(unsigned)mi.uordblks + (unsigned)mi.hblkhd; #else - return mi.uordblks; + return (unsigned)mi.uordblks; #endif #elif defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H) -- cgit 1.4.1