minor fixes

This commit is contained in:
Akash Mozumdar 2018-07-25 01:11:23 -07:00
parent 11d6a156dd
commit 11016d146a
3 changed files with 14 additions and 11 deletions

View File

@ -81,13 +81,14 @@ namespace Host
DLLEXPORT void Close() DLLEXPORT void Close()
{ {
EnterCriticalSection(&hostCs); // Artikash 7/25/2018: This is only called when NextHooker is closed, at which point Windows should free everything itself...right?
DestroyWindow(dummyWindow); //EnterCriticalSection(&hostCs);
RemoveThreads([](auto one, auto two) { return true; }, {}); //DestroyWindow(dummyWindow);
//for (auto i : processRecordsByIds) UnregisterProcess(i.first); // Artikash 7/24/2018 FIXME: This segfaults since UnregisterProcess invalidates the iterator //RemoveThreads([](auto one, auto two) { return true; }, {});
LeaveCriticalSection(&hostCs); ////for (auto i : processRecordsByIds) UnregisterProcess(i.first); // Artikash 7/24/2018 FIXME: This segfaults since UnregisterProcess invalidates the iterator
DeleteCriticalSection(&hostCs); //LeaveCriticalSection(&hostCs);
CloseHandle(preventDuplicationMutex); //DeleteCriticalSection(&hostCs);
//CloseHandle(preventDuplicationMutex);
} }
DLLEXPORT bool InjectProcess(DWORD processId, DWORD timeout) 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) 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; if (!text || !pid || len <= 0) return;
HOST_LOCK; HOST_LOCK;
ThreadParameter tp = { pid, hook, retn, split }; ThreadParameter tp = { pid, hook, retn, split };
@ -234,7 +235,7 @@ void RemoveThreads(bool(*RemoveIf)(ThreadParameter, ThreadParameter), ThreadPara
{ {
if (onRemove) onRemove(i.second); 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. //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); removedThreads.push_back(i.first);
} }
for (auto i : removedThreads) textThreadsByParams.erase(i); for (auto i : removedThreads) textThreadsByParams.erase(i);

View File

@ -32,10 +32,11 @@ TextThread::~TextThread()
DeleteCriticalSection(&ttCs); DeleteCriticalSection(&ttCs);
} }
void TextThread::Reset() void TextThread::Clear()
{ {
TT_LOCK; TT_LOCK;
storage.clear(); storage.clear();
storage.shrink_to_fit();
} }
void TextThread::AddSentence() void TextThread::AddSentence()

View File

@ -34,11 +34,12 @@ public:
TextThread(ThreadParameter tp, unsigned int threadNumber, unsigned int splitDelay = 250); TextThread(ThreadParameter tp, unsigned int threadNumber, unsigned int splitDelay = 250);
~TextThread(); ~TextThread();
void Reset(); void Clear();
void AddText(const BYTE *con, int len); void AddText(const BYTE *con, int len);
void AddSentence(); void AddSentence();
void AddSentence(std::wstring sentence); 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; } std::wstring GetStore() { return storage; }
DWORD &Status() { return status; } DWORD &Status() { return status; }
WORD Number() const { return threadNumber; } WORD Number() const { return threadNumber; }