| Index: mojo/edk/embedder/platform_handle.cc
|
| diff --git a/mojo/edk/embedder/platform_handle.cc b/mojo/edk/embedder/platform_handle.cc
|
| index 5709b1e46850936b7ccff88e3b8f15313bf7bf21..b6b2cd22d1fee38d8f38879adda8d387a7f6a237 100644
|
| --- a/mojo/edk/embedder/platform_handle.cc
|
| +++ b/mojo/edk/embedder/platform_handle.cc
|
| @@ -36,6 +36,32 @@ void PlatformHandle::CloseIfNecessary() {
|
| }
|
| #endif // defined(OS_MACOSX) && !defined(OS_IOS)
|
| #elif defined(OS_WIN)
|
| + if (owning_process != base::GetCurrentProcessHandle()) {
|
| + // This handle may have been duplicated to a new target process but not yet
|
| + // sent there. In this case CloseHandle should NOT be called. From MSDN
|
| + // documentation for DuplicateHandle[1]:
|
| + //
|
| + // Normally the target process closes a duplicated handle when that
|
| + // process is finished using the handle. To close a duplicated handle
|
| + // from the source process, call DuplicateHandle with the following
|
| + // parameters:
|
| + //
|
| + // * Set hSourceProcessHandle to the target process from the
|
| + // call that created the handle.
|
| + // * Set hSourceHandle to the duplicated handle to close.
|
| + // * Set lpTargetHandle to NULL.
|
| + // * Set dwOptions to DUPLICATE_CLOSE_SOURCE.
|
| + //
|
| + // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms724251
|
| + //
|
| + // NOTE: It's possible for this operation to fail if the owning process
|
| + // was terminated or is in the process of being terminated. Either way,
|
| + // there is nothing we can reasonably do about failure, so we ignore it.
|
| + DuplicateHandle(owning_process, handle, NULL, &handle, 0, FALSE,
|
| + DUPLICATE_CLOSE_SOURCE);
|
| + return;
|
| + }
|
| +
|
| bool success = !!CloseHandle(handle);
|
| DPCHECK(success);
|
| handle = INVALID_HANDLE_VALUE;
|
|
|