From 57702ccba3d2a844adb6745458208a81e628c01e Mon Sep 17 00:00:00 2001
From: "arseny.kapoulkine"
 <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>
Date: Sun, 9 May 2010 18:23:50 +0000
Subject: Improved memory leak detection

git-svn-id: http://pugixml.googlecode.com/svn/trunk@398 99668b35-9821-0410-8761-19e4c4f06640
---
 tests/main.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tests/main.cpp b/tests/main.cpp
index 1aeafd2..444b188 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -11,6 +11,7 @@ jmp_buf test_runner::_failure_buffer;
 const char* test_runner::_failure_message;
 
 static size_t g_memory_total_size = 0;
+static size_t g_memory_total_count = 0;
 
 static void* custom_allocate(size_t size)
 {
@@ -21,6 +22,7 @@ static void* custom_allocate(size_t size)
 		void* ptr = memory_allocate(size);
 
 		g_memory_total_size += memory_size(ptr);
+		g_memory_total_count++;
 		
 		return ptr;
 	}
@@ -31,6 +33,7 @@ static void custom_deallocate(void* ptr)
 	if (ptr)
 	{
 		g_memory_total_size -= memory_size(ptr);
+		g_memory_total_count--;
 		
 		memory_deallocate(ptr);
 	}
@@ -63,6 +66,7 @@ static bool run_test(test_runner* test)
 	{
 #endif
 		g_memory_total_size = 0;
+		g_memory_total_count = 0;
 		test_runner::_memory_fail_threshold = 0;
 	
 #ifdef _MSC_VER
@@ -84,9 +88,9 @@ static bool run_test(test_runner* test)
 
 		test->run();
 
-		if (g_memory_total_size != 0)
+		if (g_memory_total_size != 0 || g_memory_total_count != 0)
 		{
-			printf("Test %s failed: memory leaks found (%u bytes)\n", test->_name, (unsigned int)g_memory_total_size);
+			printf("Test %s failed: memory leaks found (%u bytes in %u allocations)\n", test->_name, (unsigned int)g_memory_total_size, (unsigned int)g_memory_total_count);
 			return false;
 		}
 
-- 
cgit v1.2.3