-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
vld_clr.cpp
50 lines (38 loc) · 1.17 KB
/
vld_clr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "vld_clr.h"
namespace VLD
{
int VldReportHook(int reportType, wchar_t *message, int *returnValue)
{ auto msg = gcnew String(message);
System::Diagnostics::Debug::Write(msg);
if (VisualLeakDetector::Instance)
VisualLeakDetector::Instance->ReportInternal(reportType, msg);
*returnValue = 0; /* don't debug break */
return 1; /* handled */
}
VisualLeakDetector::VisualLeakDetector() : m_messages(gcnew List<Tuple<int, String^>^>)
{ if (Instance != nullptr)
{ throw gcnew NotSupportedException("Only a single instance is supported.");
}
Instance = this;
VLDSetReportHook(VLD_RPTHOOK_INSTALL, VldReportHook);
}
VisualLeakDetector::~VisualLeakDetector()
{ this->!VisualLeakDetector();
}
VisualLeakDetector::!VisualLeakDetector()
{ VLDSetReportHook(VLD_RPTHOOK_REMOVE, VldReportHook);
Instance = nullptr;
}
void VisualLeakDetector::ReportInternal(int reportType, String^ msg)
{ m_messages->Add(Tuple::Create(reportType, msg));
}
void VisualLeakDetector::ReportLeaks()
{ VLDReportLeaks();
}
List<Tuple<int, String^>^>^ VisualLeakDetector::Messages::get()
{ return m_messages;
}
void VisualLeakDetector::MarkAllLeaksAsReported()
{ VLDMarkAllLeaksAsReported();
}
}