diff --git a/texthook/host.cc b/texthook/host.cc index ead94a6..2b5627f 100644 --- a/texthook/host.cc +++ b/texthook/host.cc @@ -81,13 +81,14 @@ namespace Host DLLEXPORT void Close() { - EnterCriticalSection(&hostCs); - DestroyWindow(dummyWindow); - RemoveThreads([](auto one, auto two) { return true; }, {}); - //for (auto i : processRecordsByIds) UnregisterProcess(i.first); // Artikash 7/24/2018 FIXME: This segfaults since UnregisterProcess invalidates the iterator - LeaveCriticalSection(&hostCs); - DeleteCriticalSection(&hostCs); - CloseHandle(preventDuplicationMutex); + // Artikash 7/25/2018: This is only called when NextHooker is closed, at which point Windows should free everything itself...right? + //EnterCriticalSection(&hostCs); + //DestroyWindow(dummyWindow); + //RemoveThreads([](auto one, auto two) { return true; }, {}); + ////for (auto i : processRecordsByIds) UnregisterProcess(i.first); // Artikash 7/24/2018 FIXME: This segfaults since UnregisterProcess invalidates the iterator + //LeaveCriticalSection(&hostCs); + //DeleteCriticalSection(&hostCs); + //CloseHandle(preventDuplicationMutex); } DLLEXPORT bool InjectProcess(DWORD processId, DWORD timeout) @@ -211,7 +212,7 @@ namespace Host void DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD split, const BYTE * text, int len) { - // jichi 20/27/2013: When PID is zero, the text comes from console, which I don't need + // jichi 2/27/2013: When PID is zero, the text comes from console, which I don't need if (!text || !pid || len <= 0) return; HOST_LOCK; ThreadParameter tp = { pid, hook, retn, split }; @@ -234,7 +235,7 @@ void RemoveThreads(bool(*RemoveIf)(ThreadParameter, ThreadParameter), ThreadPara { if (onRemove) onRemove(i.second); //delete i.second; // Artikash 7/24/2018: FIXME: Qt GUI updates on another thread, so I can't delete this yet. - i.second->Reset(); // Temp workaround to free some memory. + i.second->Clear(); // Temp workaround to free some memory. removedThreads.push_back(i.first); } for (auto i : removedThreads) textThreadsByParams.erase(i); diff --git a/texthook/textthread.cc b/texthook/textthread.cc index 1b41ddf..5a38b1d 100644 --- a/texthook/textthread.cc +++ b/texthook/textthread.cc @@ -32,10 +32,11 @@ TextThread::~TextThread() DeleteCriticalSection(&ttCs); } -void TextThread::Reset() +void TextThread::Clear() { TT_LOCK; storage.clear(); + storage.shrink_to_fit(); } void TextThread::AddSentence() diff --git a/texthook/textthread.h b/texthook/textthread.h index 219e1b7..7f3708d 100644 --- a/texthook/textthread.h +++ b/texthook/textthread.h @@ -34,11 +34,12 @@ public: TextThread(ThreadParameter tp, unsigned int threadNumber, unsigned int splitDelay = 250); ~TextThread(); - void Reset(); + void Clear(); void AddText(const BYTE *con, int len); void AddSentence(); void AddSentence(std::wstring sentence); + // Artikash 7/25/2018: Not thread-safe with Clear(), but since they should both be accessed from GUI thread, should be fine std::wstring GetStore() { return storage; } DWORD &Status() { return status; } WORD Number() const { return threadNumber; }