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

Side by Side Diff: base/win/scoped_handle.h

Issue 9700038: ScopedProcessInformation protects against process/thread handle leaks from CreateProcess calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove changes from another CL. Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_WIN_SCOPED_HANDLE_H_ 5 #ifndef BASE_WIN_SCOPED_HANDLE_H_
6 #define BASE_WIN_SCOPED_HANDLE_H_ 6 #define BASE_WIN_SCOPED_HANDLE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <windows.h> 9 #include <windows.h>
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 ~GenericScopedHandle() { 35 ~GenericScopedHandle() {
36 Close(); 36 Close();
37 } 37 }
38 38
39 bool IsValid() const { 39 bool IsValid() const {
40 return Traits::IsHandleValid(handle_); 40 return Traits::IsHandleValid(handle_);
41 } 41 }
42 42
43 void Set(Handle handle) { 43 void Set(Handle handle) {
44 if (handle_ != handle) { 44 if (!Traits::IsSame(handle_, handle)) {
45 Close(); 45 Close();
46 46
47 if (Traits::IsHandleValid(handle)) { 47 if (Traits::IsHandleValid(handle)) {
48 handle_ = handle; 48 handle_ = handle;
49 } 49 }
50 } 50 }
51 } 51 }
52 52
53 Handle Get() const { 53 Handle Get() const {
54 return handle_; 54 return handle_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Closes the handle. 94 // Closes the handle.
95 static bool CloseHandle(HANDLE handle) { 95 static bool CloseHandle(HANDLE handle) {
96 return ::CloseHandle(handle) != FALSE; 96 return ::CloseHandle(handle) != FALSE;
97 } 97 }
98 98
99 // Returns true if the handle value is valid. 99 // Returns true if the handle value is valid.
100 static bool IsHandleValid(HANDLE handle) { 100 static bool IsHandleValid(HANDLE handle) {
101 return handle != NULL && handle != INVALID_HANDLE_VALUE; 101 return handle != NULL && handle != INVALID_HANDLE_VALUE;
102 } 102 }
103 103
104 // Returns true if the handle values are the same.
105 static bool IsSame(HANDLE lhs, HANDLE rhs) {
alexeypa (please no reviews) 2012/03/15 02:41:31 We will be able to avoid changing all instances of
erikwright (departed) 2012/03/15 03:29:17 I thought about listing this as one of my proposed
106 return lhs == rhs;
107 }
108
104 // Returns NULL handle value. 109 // Returns NULL handle value.
105 static HANDLE NullHandle() { 110 static HANDLE NullHandle() {
106 return NULL; 111 return NULL;
107 } 112 }
108 113
109 private: 114 private:
110 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleTraits); 115 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleTraits);
111 }; 116 };
112 117
113 typedef GenericScopedHandle<HandleTraits> ScopedHandle; 118 typedef GenericScopedHandle<HandleTraits> ScopedHandle;
114 119
115 } // namespace win 120 } // namespace win
116 } // namespace base 121 } // namespace base
117 122
118 #endif // BASE_SCOPED_HANDLE_WIN_H_ 123 #endif // BASE_SCOPED_HANDLE_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698