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

Side by Side Diff: base/sys_info_mac.cc

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: Fix compile 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/sys_info_ios.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #include <mach/mach_host.h> 9 #include <mach/mach_host.h>
10 #include <mach/mach_init.h> 10 #include <mach/mach_init.h>
11 #include <sys/sysctl.h> 11 #include <sys/sysctl.h>
12 #include <sys/types.h> 12 #include <sys/types.h>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/mac/scoped_mach_port.h"
15 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
16 17
17 namespace base { 18 namespace base {
18 19
19 // static 20 // static
20 std::string SysInfo::OperatingSystemName() { 21 std::string SysInfo::OperatingSystemName() {
21 return "Mac OS X"; 22 return "Mac OS X";
22 } 23 }
23 24
24 // static 25 // static
(...skipping 12 matching lines...) Expand all
37 Gestalt(gestaltSystemVersionMinor, 38 Gestalt(gestaltSystemVersionMinor,
38 reinterpret_cast<SInt32*>(minor_version)); 39 reinterpret_cast<SInt32*>(minor_version));
39 Gestalt(gestaltSystemVersionBugFix, 40 Gestalt(gestaltSystemVersionBugFix,
40 reinterpret_cast<SInt32*>(bugfix_version)); 41 reinterpret_cast<SInt32*>(bugfix_version));
41 } 42 }
42 43
43 // static 44 // static
44 int64 SysInfo::AmountOfPhysicalMemory() { 45 int64 SysInfo::AmountOfPhysicalMemory() {
45 struct host_basic_info hostinfo; 46 struct host_basic_info hostinfo;
46 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; 47 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
47 int result = host_info(mach_host_self(), 48 base::mac::ScopedMachPort host(mach_host_self());
49 int result = host_info(host,
48 HOST_BASIC_INFO, 50 HOST_BASIC_INFO,
49 reinterpret_cast<host_info_t>(&hostinfo), 51 reinterpret_cast<host_info_t>(&hostinfo),
50 &count); 52 &count);
51 if (result != KERN_SUCCESS) { 53 if (result != KERN_SUCCESS) {
52 NOTREACHED(); 54 NOTREACHED();
53 return 0; 55 return 0;
54 } 56 }
55 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); 57 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
56 return static_cast<int64>(hostinfo.max_mem); 58 return static_cast<int64>(hostinfo.max_mem);
57 } 59 }
58 60
59 // static 61 // static
60 std::string SysInfo::CPUModelName() { 62 std::string SysInfo::CPUModelName() {
61 char name[256]; 63 char name[256];
62 size_t len = arraysize(name); 64 size_t len = arraysize(name);
63 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0) 65 if (sysctlbyname("machdep.cpu.brand_string", &name, &len, NULL, 0) == 0)
64 return name; 66 return name;
65 return std::string(); 67 return std::string();
66 } 68 }
67 69
68 } // namespace base 70 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_ios.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698