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

Unified Diff: runtime/vm/cpuinfo_macos.cc

Issue 1677043003: 1. Fix memory leaks reported by running a simple test using ASAN (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address-code-review Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/cpuinfo_linux.cc ('k') | runtime/vm/cpuinfo_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/cpuinfo_macos.cc
diff --git a/runtime/vm/cpuinfo_macos.cc b/runtime/vm/cpuinfo_macos.cc
index 63523914ddf4c2bd581ebe4e2edb897b2e3c46cd..508851ae0978087dc8d8eeaa8c36ab3eac0a9b7c 100644
--- a/runtime/vm/cpuinfo_macos.cc
+++ b/runtime/vm/cpuinfo_macos.cc
@@ -31,10 +31,10 @@ void CpuInfo::InitOnce() {
void CpuInfo::Cleanup() {}
-bool CpuInfo::FieldContainsByString(const char* field,
- const char* search_string) {
+bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
ASSERT(method_ != kCpuInfoDefault);
ASSERT(search_string != NULL);
+ const char* field = FieldName[idx];
char dest[1024];
size_t dest_len = 1024;
@@ -48,14 +48,9 @@ bool CpuInfo::FieldContainsByString(const char* field,
}
-bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
- ASSERT(method_ != kCpuInfoDefault);
- return FieldContainsByString(FieldName(idx), search_string);
-}
-
-
-const char* CpuInfo::ExtractFieldByString(const char* field) {
+const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
ASSERT(method_ != kCpuInfoDefault);
+ const char* field = FieldName(idx);
ASSERT(field != NULL);
size_t result_len;
@@ -65,7 +60,7 @@ const char* CpuInfo::ExtractFieldByString(const char* field) {
return 0;
}
- char* result = new char[result_len];
+ char* result = reinterpret_cast<char*>(malloc(result_len));
if (sysctlbyname(field, result, &result_len, NULL, 0) != 0) {
UNREACHABLE();
return 0;
@@ -75,12 +70,6 @@ const char* CpuInfo::ExtractFieldByString(const char* field) {
}
-const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
- ASSERT(method_ != kCpuInfoDefault);
- return ExtractFieldByString(FieldName(idx));
-}
-
-
bool CpuInfo::HasField(const char* field) {
ASSERT(method_ != kCpuInfoDefault);
ASSERT(field != NULL);
« no previous file with comments | « runtime/vm/cpuinfo_linux.cc ('k') | runtime/vm/cpuinfo_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698