boost-process icon indicating copy to clipboard operation
boost-process copied to clipboard

Potential bug in async wait process example

Open angelcarro opened this issue 9 years ago • 0 comments

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

angelcarro avatar May 15 '15 15:05 angelcarro