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

Unified Diff: runtime/bin/platform_macos.cc

Issue 1781883002: Fixes some memory leaks in //runtime/bin (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix tests on Windows Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/platform_linux.cc ('k') | runtime/bin/platform_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_macos.cc
diff --git a/runtime/bin/platform_macos.cc b/runtime/bin/platform_macos.cc
index 0f7c62965c2c829f568a7e4e862a0fd8c9c1d599..b9a1faa08ccc3fab73ee2fbf8c38f9bfa1d9d72e 100644
--- a/runtime/bin/platform_macos.cc
+++ b/runtime/bin/platform_macos.cc
@@ -89,9 +89,12 @@ char** Platform::Environment(intptr_t* count) {
char** environ = *(_NSGetEnviron());
intptr_t i = 0;
char** tmp = environ;
- while (*(tmp++) != NULL) i++;
+ while (*(tmp++) != NULL) {
+ i++;
+ }
*count = i;
- char** result = new char*[i];
+ char** result;
+ result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result)));
for (intptr_t current = 0; current < i; current++) {
result[current] = environ[current];
}
@@ -100,30 +103,23 @@ char** Platform::Environment(intptr_t* count) {
}
-void Platform::FreeEnvironment(char** env, intptr_t count) {
- delete[] env;
-}
-
-
-char* Platform::ResolveExecutablePath() {
+const char* Platform::ResolveExecutablePath() {
// Get the required length of the buffer.
uint32_t path_size = 0;
- char* path = NULL;
- if (_NSGetExecutablePath(path, &path_size) == 0) {
+ if (_NSGetExecutablePath(NULL, &path_size) == 0) {
return NULL;
}
// Allocate buffer and get executable path.
- path = reinterpret_cast<char*>(malloc(path_size));
+ char* path = DartUtils::ScopedCString(path_size);
if (_NSGetExecutablePath(path, &path_size) != 0) {
- free(path);
return NULL;
}
// Return the canonical path as the returned path might contain symlinks.
- char* canon_path = File::GetCanonicalPath(path);
- free(path);
+ const char* canon_path = File::GetCanonicalPath(path);
return canon_path;
}
+
void Platform::Exit(int exit_code) {
exit(exit_code);
}
« no previous file with comments | « runtime/bin/platform_linux.cc ('k') | runtime/bin/platform_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698