summaryrefslogtreecommitdiffstats
path: root/base/mac/scoped_mach_port.h
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 20:17:58 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 20:17:58 +0000
commit431d0a145888ee2ff1cf4aff277e78fd36924f6b (patch)
tree8f491756731bf54e280da47ae05e8c8ec69d14d3 /base/mac/scoped_mach_port.h
parent6361c61b55261a9d3b43c9991e1811ce01a89714 (diff)
downloadchromium_src-431d0a145888ee2ff1cf4aff277e78fd36924f6b.zip
chromium_src-431d0a145888ee2ff1cf4aff277e78fd36924f6b.tar.gz
chromium_src-431d0a145888ee2ff1cf4aff277e78fd36924f6b.tar.bz2
Fix some potential Mach port leaks from mach_host_self using a new ScopedMachPort class.
BUG=119379 TEST=none Review URL: https://chromiumcodereview.appspot.com/11188003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162225 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac/scoped_mach_port.h')
-rw-r--r--base/mac/scoped_mach_port.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/base/mac/scoped_mach_port.h b/base/mac/scoped_mach_port.h
new file mode 100644
index 0000000..d2aa2f7
--- /dev/null
+++ b/base/mac/scoped_mach_port.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MAC_SCOPED_MACH_PORT_H_
+#define BASE_MAC_SCOPED_MACH_PORT_H_
+
+#include <mach/mach.h>
+
+#include "base/basictypes.h"
+#include "base/base_export.h"
+
+namespace base {
+namespace mac {
+
+// A class for managing the life of a Mach port, releasing via
+// mach_port_deallocate either its send and/or receive rights.
+class BASE_EXPORT ScopedMachPort {
+ public:
+ // Creates a scoper by taking ownership of the port.
+ explicit ScopedMachPort(mach_port_t port);
+
+ ~ScopedMachPort();
+
+ operator mach_port_t() const {
+ return port_;
+ }
+
+ mach_port_t get() const {
+ return port_;
+ }
+
+ private:
+ mach_port_t port_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedMachPort);
+};
+
+} // namespace mac
+} // namespace base
+
+#endif // BASE_MAC_SCOPED_MACH_PORT_H_