Skip to content

Potential bug in async wait process example #3

@angelcarro

Description

@angelcarro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions