Chromium Code Reviews| Index: base/win/scoped_handle.cc |
| diff --git a/base/win/scoped_handle.cc b/base/win/scoped_handle.cc |
| index 2ebef320bb8b143d4f2944ac87f3afbbc4ef8c69..1a6a54e757574b17b272768c1506caa26a544cbb 100644 |
| --- a/base/win/scoped_handle.cc |
| +++ b/base/win/scoped_handle.cc |
| @@ -152,6 +152,20 @@ void ActiveVerifier::StartTracking(HANDLE handle, const void* owner, |
| if (!enabled_) |
| return; |
| + // Idea here is to make our handles non-closable until we close it ourselves. |
| + if (!::SetHandleInformation(handle, HANDLE_FLAG_PROTECT_FROM_CLOSE, |
| + HANDLE_FLAG_PROTECT_FROM_CLOSE)) { |
| + DWORD error = GetLastError(); |
| + // Even our unittests provide invalid/fabricated handles. Reducing scope |
| + // of change to only deal with valid handles. |
| + // TODO(shrikant): If this feature has to be permanent then decide right way |
| + // for unit test ScopedProcessHandleInformation. |
| + if (error != ERROR_INVALID_HANDLE) { |
|
cpu_(ooo_6.6-7.5)
2015/05/08 02:45:18
what other error would SetHandleInformation could
|
| + base::debug::Alias(&error); |
| + CHECK(false); |
| + } |
| + } |
| + |
| // Grab the thread id before the lock. |
| DWORD thread_id = GetCurrentThreadId(); |
| @@ -172,6 +186,15 @@ void ActiveVerifier::StopTracking(HANDLE handle, const void* owner, |
| if (!enabled_) |
| return; |
| + // We expect handle to be protected till this point. |
| + DWORD flags = 0; |
| + if (::GetHandleInformation(handle, &flags)) { |
| + CHECK_NE(0U, (flags & HANDLE_FLAG_PROTECT_FROM_CLOSE)); |
| + |
| + // Unprotect handle so that it could be closed. |
| + ::SetHandleInformation(handle, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0); |
| + } |
| + |
| AutoNativeLock lock(*lock_); |
| HandleMap::iterator i = map_.find(handle); |
| if (i == map_.end()) |