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

Side by Side Diff: base/mac/scoped_mach_port.h

Issue 11188003: Fix some potential Mach port leaks from mach_host_self using a new ScopedMachPort class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
« no previous file with comments | « base/base.gypi ('k') | base/process_util_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_MAC_SCOPED_MACH_PORT_H_
6 #define BASE_MAC_SCOPED_MACH_PORT_H_
7
8 #include <mach/mach.h>
9
10 #include "base/basictypes.h"
11
12 namespace base {
13 namespace mac {
14
15 // Templated class for managing the life of a Mach port, releasing via
16 // mach_port_deallocate either its send and/or receive rights. The template
17 // parameter allows for a specific kind of Mach port to be specified
18 // for specialized Mach port types.
Mark Mentovai 2012/10/16 16:17:52 But practically speaking, at least in userland, ev
Robert Sesek 2012/10/16 16:30:59 Done.
19 template <typename PortT>
20 class ScopedMachPort {
21 public:
22 ScopedMachPort() : port_(MACH_PORT_NULL) {}
23
24 explicit ScopedMachPort(mach_port_t port) : port_(port) {}
25
26 ~ScopedMachPort() {
27 if (port_ != MACH_PORT_NULL) {
28 mach_port_deallocate(mach_task_self(), port_);
29 port_ = MACH_PORT_NULL;
30 }
31 }
32
33 operator PortT() const {
34 return port_;
35 }
36
37 PortT get() const {
38 return port_;
39 }
40
41 private:
42 PortT port_;
43
44 DISALLOW_COPY_AND_ASSIGN(ScopedMachPort);
45 };
46
47 // A specialization of the base ScopedMachPort that is used for the generic
48 // mach_port_t.
49 class ScopedMachPortT : public ScopedMachPort<mach_port_t> {
Mark Mentovai 2012/10/16 16:17:52 If you’re going to do the templated thing, why bot
Robert Sesek 2012/10/16 16:30:59 Removed.
50 };
51
52 } // namespace mac
53 } // namespace base
54
55 #endif // BASE_MAC_SCOPED_MACH_PORT_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/process_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698