boost-process
boost-process copied to clipboard
Potential bug in async wait process example
In boost-process/libs/process/example/wait.cpp:52 , the class boost::asio::windows::object_handle is used with the child process handle. I think CloseHandle() will be called twice with the same process handle in the destructors of boost::process::child and boost::asio::windows::object_handle.
DuplicateHandle() can be used to avoid the problem:
#if defined(BOOST_WINDOWS_API)
DWORD exit_code;
HANDLE dupHandle;
DuplicateHandle(GetCurrentProcess(),c.process_handle(),GetCurrentProcess(),&dupHandle,
0,false,DUPLICATE_SAME_ACCESS));
boost::asio::windows::object_handle handle(io_service, dupHandle);
handle.async_wait(
[&handle, &exit_code](const boost::system::error_code&)
{ ::GetExitCodeProcess(handle.native(), &exit_code); }
);
#endif