diff --git a/sourcehook/sh_tinyhash.h b/sourcehook/sh_tinyhash.h index efb5c1a..8241be9 100644 --- a/sourcehook/sh_tinyhash.h +++ b/sourcehook/sh_tinyhash.h @@ -251,6 +251,7 @@ namespace SourceHook // Remove this element and move to the next one iterator tmp = *this; ++tmp; + delete (*iter); hash->m_Buckets[curbucket]->erase(iter); *this = tmp; diff --git a/sourcehook/sourcehook.cpp b/sourcehook/sourcehook.cpp index b79ce3f..ea35bac 100644 --- a/sourcehook/sourcehook.cpp +++ b/sourcehook/sourcehook.cpp @@ -751,6 +751,12 @@ namespace SourceHook delete m_FreeIters; m_FreeIters = iter; } + while (m_UsedIters) + { + CIter *iter = m_UsedIters->m_pNext; + delete m_UsedIters; + m_UsedIters = iter; + } } IHookList::IIter *CSourceHookImpl::CHookList::GetIter() { diff --git a/sourcehook/test/main.cpp b/sourcehook/test/main.cpp index ec652ef..abe10d1 100644 --- a/sourcehook/test/main.cpp +++ b/sourcehook/test/main.cpp @@ -1,6 +1,7 @@ // Hello BAIL! // hello pm how are you // I'm fine, what about you? +// not bad, just looking for mem leaks // This is a test file #include @@ -11,6 +12,7 @@ #include "sh_tinyhash.h" #include "sh_list.h" #include "sourcehook_impl.h" +#include "sourcehook.h" using namespace std; diff --git a/sourcehook/test/test1.cpp b/sourcehook/test/test1.cpp index 925d3a5..d7e50f9 100644 --- a/sourcehook/test/test1.cpp +++ b/sourcehook/test/test1.cpp @@ -675,6 +675,9 @@ bool TestBasic(std::string &error) SH_REMOVE_HOOK_MEMFUNC(Test, F8, pTest, &f1_handlers, &HandlersF1::Pre, false); SH_REMOVE_HOOK_MEMFUNC(Test, F9, pTest, &f1_handlers, &HandlersF1::Pre, false); SH_REMOVE_HOOK_MEMFUNC(Test, F10, pTest, &f1_handlers, &HandlersF1::Pre, false); + + g_SHImpl.CompleteShutdown(); + return true; } diff --git a/sourcehook/test/testreentr.cpp b/sourcehook/test/testreentr.cpp index e458c3e..2acf1da 100644 --- a/sourcehook/test/testreentr.cpp +++ b/sourcehook/test/testreentr.cpp @@ -579,6 +579,23 @@ bool TestReentr(std::string &error) new State_C1_F(g_pC1), NULL), "7"); + SH_REMOVE_HOOK_STATICFUNC(C1, F, g_pC1, Handler_C1_F, false); + SH_REMOVE_HOOK_STATICFUNC(C1, G, g_pC1, Handler_C1_G, false); + SH_REMOVE_HOOK_STATICFUNC(C2, F, g_pC2, Handler_C2_F, false); + SH_REMOVE_HOOK_STATICFUNC(C2, G, g_pC2, Handler_C2_G, false); + SH_REMOVE_HOOK_STATICFUNC(C3, F, g_pC3, Handler_C3_F, false); + SH_REMOVE_HOOK_STATICFUNC(C3, G, g_pC3, Handler_C3_G, false); + SH_REMOVE_HOOK_STATICFUNC(C4, F, g_pC4, Handler_C4_F, false); + SH_REMOVE_HOOK_STATICFUNC(C4, G, g_pC4, Handler_C4_G, false); + SH_REMOVE_HOOK_STATICFUNC(C5, F, g_pC5, Handler_C5_F, false); + SH_REMOVE_HOOK_STATICFUNC(C5, G, g_pC5, Handler_C5_G, false); + SH_REMOVE_HOOK_STATICFUNC(C6, F, g_pC6, Handler_C6_F, false); + SH_REMOVE_HOOK_STATICFUNC(C6, G, g_pC6, Handler_C6_G, false); + SH_REMOVE_HOOK_STATICFUNC(C7, F, g_pC7, Handler_C7_F, false); + SH_REMOVE_HOOK_STATICFUNC(C7, G, g_pC7, Handler_C7_G, false); + SH_REMOVE_HOOK_STATICFUNC(C8, F, g_pC8, Handler_C8_F, false); + SH_REMOVE_HOOK_STATICFUNC(C8, G, g_pC8, Handler_C8_G, false); + return true; }