mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 02:53:10 +01:00
Don't call CloseHandle() twice on Windows (as it causes crashes, or unexpected behavior). This would happen with the following test case:
ProcessHandle handle = Process.launch(...); handle.kill(); Then as handle gets out of scope, ~ProcessHandle would call CloseHandle() on an already closed handle.
This commit is contained in:
@@ -57,9 +57,17 @@ ProcessHandleImpl::ProcessHandleImpl(HANDLE hProcess, UInt32 pid):
|
||||
|
||||
ProcessHandleImpl::~ProcessHandleImpl()
|
||||
{
|
||||
CloseHandle(_hProcess);
|
||||
closeHandle();
|
||||
}
|
||||
|
||||
void ProcessHandleImpl::closeHandle()
|
||||
{
|
||||
if (_hProcess)
|
||||
{
|
||||
CloseHandle(_hProcess);
|
||||
_hProcess = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 ProcessHandleImpl::id() const
|
||||
{
|
||||
@@ -234,17 +242,19 @@ ProcessHandleImpl* ProcessImpl::launchImpl(const std::string& command, const Arg
|
||||
}
|
||||
|
||||
|
||||
void ProcessImpl::killImpl(const ProcessHandleImpl& handle)
|
||||
void ProcessImpl::killImpl(ProcessHandleImpl& handle)
|
||||
{
|
||||
if (TerminateProcess(handle.process(), 0) == 0)
|
||||
if (handle.process())
|
||||
{
|
||||
CloseHandle(handle.process());
|
||||
throw SystemException("cannot kill process");
|
||||
if (TerminateProcess(handle.process(), 0) == 0)
|
||||
{
|
||||
handle.closeHandle();
|
||||
throw SystemException("cannot kill process");
|
||||
}
|
||||
handle.closeHandle();
|
||||
}
|
||||
CloseHandle(handle.process());
|
||||
}
|
||||
|
||||
|
||||
void ProcessImpl::killImpl(PIDImpl pid)
|
||||
{
|
||||
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||
|
||||
Reference in New Issue
Block a user