diff options
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/directoryentry.cpp | 7 | ||||
| -rw-r--r-- | src/shared/gameinfo.cpp | 7 | ||||
| -rw-r--r-- | src/shared/gameinfo.h | 4 | ||||
| -rw-r--r-- | src/shared/leaktrace.cpp | 38 | ||||
| -rw-r--r-- | src/shared/leaktrace.h | 4 | ||||
| -rw-r--r-- | src/shared/shared.pro | 10 |
6 files changed, 55 insertions, 15 deletions
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index bd33fef6..8380181f 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -568,8 +568,9 @@ void DirectoryEntry::removeDirRecursive() for (auto iter = m_SubDirectories.begin(); iter != m_SubDirectories.end(); ++iter) {
(*iter)->removeDirRecursive();
+ delete *iter;
}
- m_SubDirectories.clear();
+ m_SubDirectories.clear();
}
void DirectoryEntry::removeDir(const std::wstring &path)
@@ -578,8 +579,10 @@ void DirectoryEntry::removeDir(const std::wstring &path) if (pos == std::string::npos) {
for (auto iter = m_SubDirectories.begin(); iter != m_SubDirectories.end(); ++iter) {
if (_wcsicmp((*iter)->getName().c_str(), path.c_str()) == 0) {
- (*iter)->removeDirRecursive();
+ DirectoryEntry *entry = *iter;
+ entry->removeDirRecursive();
m_SubDirectories.erase(iter);
+ delete entry;
break;
}
}
diff --git a/src/shared/gameinfo.cpp b/src/shared/gameinfo.cpp index 6b53450d..f74e52b4 100644 --- a/src/shared/gameinfo.cpp +++ b/src/shared/gameinfo.cpp @@ -40,6 +40,13 @@ GameInfo* GameInfo::s_Instance = NULL; GameInfo::GameInfo(const std::wstring &omoDirectory, const std::wstring &gameDirectory)
: m_GameDirectory(gameDirectory), m_OrganizerDirectory(omoDirectory)
{
+ atexit(&cleanup);
+}
+
+
+void GameInfo::cleanup() {
+ delete GameInfo::s_Instance;
+ GameInfo::s_Instance = NULL;
}
diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index 3e022ef4..14f52f05 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -176,9 +176,11 @@ private: static bool identifyGame(const std::wstring &omoDirectory, const std::wstring &searchPath);
std::wstring getSpecialPath(LPCWSTR name) const;
+ static void cleanup();
+
private:
- static GameInfo* s_Instance;
+ static GameInfo *s_Instance;
std::wstring m_MyGamesDirectory;
diff --git a/src/shared/leaktrace.cpp b/src/shared/leaktrace.cpp index 0c618b68..c3721557 100644 --- a/src/shared/leaktrace.cpp +++ b/src/shared/leaktrace.cpp @@ -3,6 +3,7 @@ #include <DbgHelp.h>
#include <set>
#include <map>
+#include <vector>
#include <sstream>
@@ -32,8 +33,18 @@ class StackData { friend bool operator==(const StackData &LHS, const StackData &RHS);
friend bool operator<(const StackData &LHS, const StackData &RHS);
public:
- StackData() {
+
+ StackData()
+ : m_FunctionName("Dummy"), m_CodeLine(0)
+ {}
+ StackData(const char *functionName, int line) {
m_Count = ::CaptureStackBackTrace(FRAMES_TO_SKIP, FRAMES_TO_CAPTURE, m_Stack, &m_Hash);
+ m_FunctionName = functionName;
+ m_CodeLine = line;
+ if (m_Count == 0) {
+ // TODO in this case the hash doesn't seem to be set. This is of course not a good solution
+ m_Hash = reinterpret_cast<unsigned long>(m_FunctionName) + m_CodeLine;
+ }
}
std::string toString() const {
initDbgIfNecessary();
@@ -45,6 +56,8 @@ public: std::ostringstream stackStream;
+ stackStream << m_FunctionName << " [" << m_CodeLine << "]\n";
+
for(unsigned int i = 0; i < m_Count; ++i) {
DWORD64 displacement = 0;
if (!::SymFromAddr(::GetCurrentProcess(), (DWORD64)m_Stack[i], &displacement, symbol)) {
@@ -59,6 +72,8 @@ private: LPVOID m_Stack[FRAMES_TO_CAPTURE];
USHORT m_Count;
ULONG m_Hash;
+ const char *m_FunctionName;
+ int m_CodeLine;
};
bool operator==(const StackData &LHS, const StackData &RHS) {
@@ -70,10 +85,9 @@ bool operator<(const StackData &LHS, const StackData &RHS) { }
-
static struct __TraceData {
- void regTrace(void *pointer) {
- m_Traces[reinterpret_cast<unsigned long>(pointer)] = StackData();
+ void regTrace(void *pointer, const char *functionName, int line) {
+ m_Traces[reinterpret_cast<unsigned long>(pointer)] = StackData(functionName, line);
}
void deregTrace(void *pointer) {
auto iter = m_Traces.find(reinterpret_cast<unsigned long>(pointer));
@@ -83,24 +97,30 @@ static struct __TraceData { }
~__TraceData() {
- std::map<StackData, int> result;
+ std::map<StackData, std::vector<unsigned long> > result;
for (auto iter = m_Traces.begin(); iter != m_Traces.end(); ++iter) {
- result[iter->second] += 1;
+ result[iter->second].push_back(iter->first);
}
for (auto iter = result.begin(); iter != result.end(); ++iter) {
printf("-----------------------------------\n"
"%d objects not freed, allocated at:\n%s",
- iter->second, iter->first.toString().c_str());
+ iter->second.size(), iter->first.toString().c_str());
+ printf("Addresses: ");
+ for (int i = 0; i < (std::min<int>)(5, iter->second.size()); ++i) {
+ printf("%p, ", iter->second[i]);
+ }
+ printf("\n");
}
}
std::map<unsigned long, StackData> m_Traces;
+
} __trace;
-void LeakTrace::TraceAlloc(void *ptr)
+void LeakTrace::TraceAlloc(void *ptr, const char *functionName, int line)
{
- __trace.regTrace(ptr);
+ __trace.regTrace(ptr, functionName, line);
}
void LeakTrace::TraceDealloc(void *ptr)
diff --git a/src/shared/leaktrace.h b/src/shared/leaktrace.h index 78764260..4985925e 100644 --- a/src/shared/leaktrace.h +++ b/src/shared/leaktrace.h @@ -4,14 +4,14 @@ namespace LeakTrace {
-void TraceAlloc(void *ptr);
+void TraceAlloc(void *ptr, const char *functionName, int line);
void TraceDealloc(void *ptr);
};
#ifdef TRACE_LEAKS
-#define LEAK_TRACE LeakTrace::TraceAlloc(this)
+#define LEAK_TRACE LeakTrace::TraceAlloc(this, __FUNCTION__, __LINE__)
#define LEAK_UNTRACE LeakTrace::TraceDealloc(this)
#else // TRACE_LEAKS
diff --git a/src/shared/shared.pro b/src/shared/shared.pro index ab0bd8a0..992fd7f2 100644 --- a/src/shared/shared.pro +++ b/src/shared/shared.pro @@ -13,9 +13,17 @@ CONFIG += staticlib INCLUDEPATH += ../bsatk "$(BOOSTPATH)"
+
+# only for custom leak detection
+#DEFINES += TRACE_LEAKS
+#LIBS += -lDbgHelp
+
+
CONFIG(debug, debug|release) {
- LIBS += -L$$OUT_PWD/../bsatk/debug
+ LIBS += -L$$OUT_PWD/../bsatk/debug
LIBS += -lDbgHelp
+ QMAKE_CXXFLAGS_DEBUG -= -Zi
+ QMAKE_CXXFLAGS += -Z7
} else {
LIBS += -L$$OUT_PWD/../bsatk/release
}
|
