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

Unified Diff: runtime/bin/process.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_win.cc ('k') | runtime/bin/process_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process.cc
diff --git a/runtime/bin/process.cc b/runtime/bin/process.cc
index b58304952cd4193e4ffcb88bbc0b5bd19a35c419..4a87e296e9d5255dbe38258488bc5df39ae60ded 100644
--- a/runtime/bin/process.cc
+++ b/runtime/bin/process.cc
@@ -47,11 +47,12 @@ static char** ExtractCStringList(Dart_Handle strings,
return NULL;
}
*length = len;
- char** string_args = new char*[len];
+ char** string_args;
+ string_args = reinterpret_cast<char**>(
+ Dart_ScopeAllocate(len * sizeof(*string_args)));
for (int i = 0; i < len; i++) {
Dart_Handle arg = Dart_ListGetAt(strings, i);
if (Dart_IsError(arg)) {
- delete[] string_args;
Dart_PropagateError(arg);
}
if (!Dart_IsString(arg)) {
@@ -64,7 +65,6 @@ static char** ExtractCStringList(Dart_Handle strings,
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
- delete[] string_args;
return NULL;
}
string_args[i] = const_cast<char *>(DartUtils::GetStringValue(arg));
@@ -115,7 +115,6 @@ void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) {
if (Dart_IsString(working_directory_handle)) {
working_directory = DartUtils::GetStringValue(working_directory_handle);
} else if (!Dart_IsNull(working_directory_handle)) {
- delete[] string_args;
result = DartUtils::SetIntegerField(status_handle, "_errorCode", 0);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
@@ -139,7 +138,6 @@ void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) {
"Environment values must be builtin strings",
&environment_length);
if (string_environment == NULL) {
- delete[] string_args;
Dart_SetReturnValue(args, Dart_NewBoolean(false));
return;
}
@@ -151,7 +149,7 @@ void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) {
Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 8);
Dart_Handle exit_handle = Dart_GetNativeArgument(args, 9);
intptr_t pid = -1;
- char* os_error_message = NULL;
+ char* os_error_message = NULL; // Scope allocated by Process::Start.
int error_code = Process::Start(path,
string_args,
@@ -188,15 +186,9 @@ void FUNCTION_NAME(Process_Start)(Dart_NativeArguments args) {
os_error_message != NULL ? os_error_message
: "Cannot get error message");
if (Dart_IsError(result)) {
- delete[] string_args;
- delete[] string_environment;
- free(os_error_message);
Dart_PropagateError(result);
}
}
- delete[] string_args;
- delete[] string_environment;
- free(os_error_message);
Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0));
}
@@ -221,9 +213,13 @@ void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) {
exit_event,
&result)) {
Dart_Handle out = result.stdout_data();
- if (Dart_IsError(out)) Dart_PropagateError(out);
+ if (Dart_IsError(out)) {
+ Dart_PropagateError(out);
+ }
Dart_Handle err = result.stderr_data();
- if (Dart_IsError(err)) Dart_PropagateError(err);
+ if (Dart_IsError(err)) {
+ Dart_PropagateError(err);
+ }
Dart_Handle list = Dart_NewList(4);
Dart_ListSetAt(list, 0, Dart_NewInteger(pid));
Dart_ListSetAt(list, 1, Dart_NewInteger(result.exit_code()));
@@ -323,25 +319,24 @@ void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) {
Dart_Handle bytes = Dart_GetNativeArgument(args, 0);
intptr_t bytes_length = 0;
Dart_Handle result = Dart_ListLength(bytes, &bytes_length);
- if (Dart_IsError(result)) Dart_PropagateError(result);
- uint8_t* buffer =
- reinterpret_cast<uint8_t*>(Dart_ScopeAllocate(bytes_length + 1));
+ if (Dart_IsError(result)) {
+ Dart_PropagateError(result);
+ }
+ uint8_t* buffer = Dart_ScopeAllocate(bytes_length + 1);
result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length);
buffer[bytes_length] = '\0';
- if (Dart_IsError(result)) Dart_PropagateError(result);
+ if (Dart_IsError(result)) {
+ Dart_PropagateError(result);
+ }
intptr_t len;
- char* str =
- StringUtils::ConsoleStringToUtf8(
- reinterpret_cast<char*>(buffer),
- bytes_length,
- &len);
+ char* str = StringUtils::ConsoleStringToUtf8(
+ reinterpret_cast<char*>(buffer), bytes_length, &len);
if (str == NULL) {
Dart_ThrowException(
DartUtils::NewInternalError("SystemEncodingToString failed"));
}
result =
Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len);
- free(str);
Dart_SetReturnValue(args, result);
}
@@ -368,7 +363,6 @@ void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) {
memmove(buffer, system_string, system_len);
}
Dart_SetReturnValue(args, external_array);
- free(const_cast<char*>(system_string));
}
} // namespace bin
« no previous file with comments | « runtime/bin/platform_win.cc ('k') | runtime/bin/process_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698