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

Unified Diff: runtime/bin/platform_win.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_macos.cc ('k') | runtime/bin/process.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_win.cc
diff --git a/runtime/bin/platform_win.cc b/runtime/bin/platform_win.cc
index 9b29cb726f51d06c72d96c90befd5e58dec16c6a..9bc01bc48621d3e7d1ee501ea5ebd623337c3f4a 100644
--- a/runtime/bin/platform_win.cc
+++ b/runtime/bin/platform_win.cc
@@ -47,7 +47,9 @@ bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
#if defined(PLATFORM_DISABLE_SOCKET)
return false;
#else
- if (!Socket::Initialize()) return false;
+ if (!Socket::Initialize()) {
+ return false;
+ }
return gethostname(buffer, buffer_length) == 0;
#endif
}
@@ -55,7 +57,9 @@ bool Platform::LocalHostname(char *buffer, intptr_t buffer_length) {
char** Platform::Environment(intptr_t* count) {
wchar_t* strings = GetEnvironmentStringsW();
- if (strings == NULL) return NULL;
+ if (strings == NULL) {
+ return NULL;
+ }
wchar_t* tmp = strings;
intptr_t i = 0;
while (*tmp != '\0') {
@@ -63,15 +67,20 @@ char** Platform::Environment(intptr_t* count) {
// These are synthetic variables corresponding to dynamic environment
// variables like %=C:% and %=ExitCode%, and the Dart environment does
// not include these.
- if (*tmp != '=') i++;
+ if (*tmp != '=') {
+ i++;
+ }
tmp += (wcslen(tmp) + 1);
}
*count = i;
- char** result = new char*[i];
+ char** result;
+ result = reinterpret_cast<char**>(Dart_ScopeAllocate(i * sizeof(*result)));
tmp = strings;
for (intptr_t current = 0; current < i;) {
// Skip the strings that were not counted above.
- if (*tmp != '=') result[current++] = StringUtilsWin::WideToUtf8(tmp);
+ if (*tmp != '=') {
+ result[current++] = StringUtilsWin::WideToUtf8(tmp);
+ }
tmp += (wcslen(tmp) + 1);
}
FreeEnvironmentStringsW(strings);
@@ -79,36 +88,27 @@ char** Platform::Environment(intptr_t* count) {
}
-void Platform::FreeEnvironment(char** env, intptr_t count) {
- for (intptr_t i = 0; i < count; i++) {
- free(env[i]);
- }
- delete[] env;
-}
-
-
-char* Platform::ResolveExecutablePath() {
+const char* Platform::ResolveExecutablePath() {
// GetModuleFileNameW cannot directly provide information on the
// required buffer size, so start out with a buffer large enough to
// hold any Windows path.
const int kTmpBufferSize = 32768;
- wchar_t* tmp_buffer = reinterpret_cast<wchar_t*>(malloc(kTmpBufferSize));
+ wchar_t* tmp_buffer =
+ reinterpret_cast<wchar_t*>(Dart_ScopeAllocate(kTmpBufferSize));
// Ensure no last error before calling GetModuleFileNameW.
SetLastError(ERROR_SUCCESS);
// Get the required length of the buffer.
int path_length = GetModuleFileNameW(NULL, tmp_buffer, kTmpBufferSize);
if (GetLastError() != ERROR_SUCCESS) {
- free(tmp_buffer);
return NULL;
}
char* path = StringUtilsWin::WideToUtf8(tmp_buffer);
- free(tmp_buffer);
// 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) {
// TODO(zra): Remove once VM shuts down cleanly.
::dart::private_flag_windows_run_tls_destructors = false;
« no previous file with comments | « runtime/bin/platform_macos.cc ('k') | runtime/bin/process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698