From ab037ef1c53d2779b2df16ea4d86f71f4bce6b98 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 4 Mar 2018 21:11:25 +0100 Subject: [PATCH] don't close process and file handles in ForceClose --- TitanEngine/TitanEngine.Debugger.Control.cpp | 9 -------- TitanEngine/TitanEngine.Debugger.cpp | 22 ++++++++++++++------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/TitanEngine/TitanEngine.Debugger.Control.cpp b/TitanEngine/TitanEngine.Debugger.Control.cpp index 6a05066..c541b17 100644 --- a/TitanEngine/TitanEngine.Debugger.Control.cpp +++ b/TitanEngine/TitanEngine.Debugger.Control.cpp @@ -9,17 +9,8 @@ __declspec(dllexport) void TITCALL ForceClose() { //manage process list - int processcount = (int)hListProcess.size(); - for(int i = 0; i < processcount; i++) - { - EngineCloseHandle(hListProcess.at(i).hFile); - EngineCloseHandle(hListProcess.at(i).hProcess); - } ClearProcessList(); //manage thread list - int threadcount = (int)hListThread.size(); - for(int i = 0; i < threadcount; i++) - EngineCloseHandle(hListThread.at(i).hThread); ClearThreadList(); //manage library list int libcount = (int)hListLibrary.size(); diff --git a/TitanEngine/TitanEngine.Debugger.cpp b/TitanEngine/TitanEngine.Debugger.cpp index af3f961..3dc4ecd 100644 --- a/TitanEngine/TitanEngine.Debugger.cpp +++ b/TitanEngine/TitanEngine.Debugger.cpp @@ -517,14 +517,24 @@ __declspec(dllexport) void* TITCALL InitDLLDebugW(wchar_t* szFileName, bool Rese __declspec(dllexport) bool TITCALL StopDebug() { - if(dbgProcessInformation.hProcess != NULL) + bool result = false; + HANDLE hProcess = TitanOpenProcess(PROCESS_TERMINATE, FALSE, dbgProcessInformation.dwProcessId); + if(hProcess) { - TerminateThread(dbgProcessInformation.hThread, NULL); - TerminateProcess(dbgProcessInformation.hProcess, NULL); - Sleep(10); //allow thread switching - return true; + TerminateProcess(hProcess, 0); + CloseHandle(hProcess); + result = true; } - return false; + + HANDLE hThread = TitanOpenThread(THREAD_TERMINATE, FALSE, dbgProcessInformation.dwThreadId); + if(hThread) + { + TerminateThread(hThread, 0); + CloseHandle(hThread); + Sleep(10); //allow thread switching + result = true; + } + return result; } __declspec(dllexport) bool TITCALL AttachDebugger(DWORD ProcessId, bool KillOnExit, LPVOID DebugInfo, LPVOID CallBack)