Chromium Code Reviews| Index: mojo/edk/system/channel.cc |
| diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc |
| index a03668ba1af72f281f72889555ddc4a104c8f35c..7cef6d4da0e12bb1c1c624a8668fb8491c3d7a42 100644 |
| --- a/mojo/edk/system/channel.cc |
| +++ b/mojo/edk/system/channel.cc |
| @@ -331,15 +331,23 @@ bool Channel::Message::RewriteHandles(base::ProcessHandle from_process, |
| DLOG(ERROR) << "Refusing to duplicate invalid handle."; |
| continue; |
| } |
| + CHECK_NE(handles[i].handle, INVALID_HANDLE_VALUE); |
|
Ken Rockot(use gerrit already)
2016/05/03 16:46:49
Just noticing that this can't be reached given the
|
| DCHECK_EQ(handles[i].owning_process, from_process); |
| BOOL result = DuplicateHandle( |
| from_process, handles[i].handle, to_process, |
| &handles[i].handle, 0, FALSE, |
| DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); |
| - if (result) |
| + if (result) { |
| handles[i].owning_process = to_process; |
| - else |
| + } else { |
| success = false; |
| + |
| + // If handle duplication fails, the source handle will already be closed |
| + // due to DUPLICATE_CLOSE_SOURCE. Replace the handle in the message with |
| + // an invalid handle. |
| + handles[i].handle = INVALID_HANDLE_VALUE; |
| + handles[i].owning_process = base::GetCurrentProcessHandle(); |
| + } |
| } |
| return success; |
| } |