Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: mojo/edk/embedder/platform_handle.cc

Issue 1914053003: [mojo-edk] Fix lifetime management of rewritten Windows HANDLEs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/embedder/platform_handle.h ('k') | mojo/edk/system/channel.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « mojo/edk/embedder/platform_handle.h ('k') | mojo/edk/system/channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698