Skip to content

Commit 882e508

Browse files
committed
Re-factored constuctor to be slightly cleaner, fixed double memory leak final report and added comments for issue #20.
1 parent ea28f8a commit 882e508

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

test/TestClass.hpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class TestClass
8383
}
8484
else if (GetSharedData().GetLogger() == NULL)
8585
{
86-
// Force logger to be created before memory leak checking starts.
86+
// Force logger to be created before memory leak checking starts,
87+
// so that this does not get recorded in the start/end memory checking.
8788
LogWriteLine("Unable to create logging!");
8889
}
8990

@@ -96,11 +97,8 @@ class TestClass
9697
// but after the previous test has the memory leak checking stopped.
9798
StartLeakChecking();
9899

99-
privateIncConstruction();
100-
101-
SetClassName(class_name);
102-
SetFunctionName(function_name);
103-
SetArgs(args);
100+
privateSetupPostLeakCheckingData(class_name, function_name, args);
101+
privateIncrementCounters();
104102

105103
// Start the setup part of a fixture, after leak detection starts.
106104
Setup();
@@ -123,7 +121,7 @@ class TestClass
123121

124122
// Clear the logger to ensure the allocation
125123
// for the first test is freed.
126-
privateClearSharedData();
124+
GetSharedData().Clear();
127125

128126
// Any memory leaks will get reported by dumping
129127
// all information supported for the platform,
@@ -340,8 +338,6 @@ class TestClass
340338
{
341339
privateStopLeakChecking();
342340
privateLogLeaks();
343-
if (IsLast())
344-
m_leak_check.DumpAll();
345341
}
346342

347343
template<typename T>
@@ -952,26 +948,27 @@ class TestClass
952948
}
953949
}
954950

955-
// Every function or member function test calls this construct function,
956-
// which sets up the initial logger and keeps track of number of tests.
957-
void privateIncConstruction()
951+
// This data needs to be set after leak checking so that
952+
// dynamic data is not falsely reported as a memory leak.
953+
void privateSetupPostLeakCheckingData(char const* class_name,
954+
char const* function_name,
955+
char const* args)
958956
{
959-
if (GetSharedData().GetLogger() == NULL)
960-
LogWriteLine("Error setting logger!");
957+
SetClassName(class_name);
958+
SetFunctionName(function_name);
959+
SetArgs(args);
960+
}
961961

962+
// Keep track of constructions,
963+
// totals and current test number for every test.
964+
void privateIncrementCounters()
965+
{
962966
GetSharedData().IncConstructions();
963967
GetSharedData().IncTotalTests();
964968

965969
m_test_number = GetSharedData().GetConstructions();
966970
}
967971

968-
static void privateClearSharedData()
969-
{
970-
// Free shared pointers to prevent false positives
971-
// for memory leak detection.
972-
GetSharedData().Clear();
973-
}
974-
975972
void privateSetFilename(TestString const& filename)
976973
{
977974
m_filename = filename;
@@ -1051,10 +1048,12 @@ class TestClass
10511048
// The amount of time to run the performance test.
10521049
TestTime m_sample_time;
10531050

1054-
// total checks for this function.
1051+
// Total checks for this function.
10551052
ocl_size_type m_check_count;
10561053

1057-
// test failures for this function.
1054+
// Test failures for this function.
1055+
// Only record check or timing failures as these have specific tests.
1056+
// Memory leaks do not affect this failure count.
10581057
ocl_size_type m_failure_check_count;
10591058
TestString m_check_failures;
10601059

test/TestMemoryLeakCheck_msvc.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ struct TestMemoryLeakCheck
134134
void DumpAll()
135135
{
136136
_CrtDumpMemoryLeaks();
137+
138+
// Already reported leaks, so prevent Visual Studio reporting them again.
139+
_CrtSetDbgFlag(0);
137140
}
138141

139142
template<typename T>

0 commit comments

Comments
 (0)