diff --git a/compiler-rt/lib/asan/asan_stats.cpp b/compiler-rt/lib/asan/asan_stats.cpp index 9a715ea76fee7..78cb30ec763d8 100644 --- a/compiler-rt/lib/asan/asan_stats.cpp +++ b/compiler-rt/lib/asan/asan_stats.cpp @@ -142,7 +142,7 @@ uptr __sanitizer_get_current_allocated_bytes() { uptr freed = stats.freed; // Return sane value if malloced < freed due to racy // way we update accumulated stats. - return (malloced > freed) ? malloced - freed : 1; + return (malloced > freed) ? malloced - freed : 0; } uptr __sanitizer_get_heap_size() { @@ -161,7 +161,7 @@ uptr __sanitizer_get_free_bytes() { + stats.malloced_redzones; // Return sane value if total_free < total_used due to racy // way we update accumulated stats. - return (total_free > total_used) ? total_free - total_used : 1; + return (total_free > total_used) ? total_free - total_used : 0; } uptr __sanitizer_get_unmapped_bytes() { diff --git a/compiler-rt/test/asan/TestCases/Posix/current_allocated_bytes.cpp b/compiler-rt/test/asan/TestCases/Posix/current_allocated_bytes.cpp index c49e433b1e8bf..7c83dc6106f38 100644 --- a/compiler-rt/test/asan/TestCases/Posix/current_allocated_bytes.cpp +++ b/compiler-rt/test/asan/TestCases/Posix/current_allocated_bytes.cpp @@ -17,7 +17,7 @@ void* allocate(void *arg) { } void* check_stats(void *arg) { - assert(__sanitizer_get_current_allocated_bytes() > 0); + assert(__sanitizer_get_current_allocated_bytes() >= 0); return 0; }