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

Unified Diff: runtime/bin/process_macos.cc

Issue 8659032: Fix memory leak in MacOS process handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years, 1 month 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/process_linux.cc ('k') | runtime/bin/socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_macos.cc
diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc
index 9a1d178864d969416f65c13f7c5bb362f323e9c1..eced5f82085dc282bc2588e85a8281e6bd872dcd 100644
--- a/runtime/bin/process_macos.cc
+++ b/runtime/bin/process_macos.cc
@@ -52,7 +52,7 @@ static ProcessInfo* LookupProcess(pid_t pid) {
}
-static ProcessInfo* RemoveProcess(pid_t pid) {
+static void RemoveProcess(pid_t pid) {
ProcessInfo* prev = NULL;
ProcessInfo* current = active_processes;
while (current != NULL) {
@@ -62,12 +62,12 @@ static ProcessInfo* RemoveProcess(pid_t pid) {
} else {
prev->set_next(current->next());
}
- return current;
+ delete current;
+ return;
}
prev = current;
current = current->next();
}
- return NULL;
}
@@ -115,6 +115,24 @@ void ExitHandler(int process_signal, siginfo_t* siginfo, void* tmp) {
}
+static void ReportChildError(int exec_control_fd) {
+ // In the case of failure in the child process write the errno and
+ // the OS error message to the exec control pipe and exit.
+ int child_errno = errno;
+ char* os_error_message = strerror(errno);
+ ASSERT(sizeof(child_errno) == sizeof(errno));
+ int bytes_written =
+ FDUtils::WriteToBlocking(
+ exec_control_fd, &child_errno, sizeof(child_errno));
+ if (bytes_written == sizeof(child_errno)) {
+ FDUtils::WriteToBlocking(
+ exec_control_fd, os_error_message, strlen(os_error_message) + 1);
+ }
+ close(exec_control_fd);
+ exit(1);
+}
+
+
int Process::Start(const char* path,
char* arguments[],
intptr_t arguments_length,
@@ -230,30 +248,23 @@ int Process::Start(const char* path,
close(read_err[0]);
close(exec_control[0]);
- dup2(write_out[0], STDIN_FILENO);
+ if (dup2(write_out[0], STDIN_FILENO) == -1) {
+ ReportChildError(exec_control[1]);
+ }
close(write_out[0]);
- dup2(read_in[1], STDOUT_FILENO);
+ if (dup2(read_in[1], STDOUT_FILENO) == -1) {
+ ReportChildError(exec_control[1]);
+ }
close(read_in[1]);
- dup2(read_err[1], STDERR_FILENO);
+ if (dup2(read_err[1], STDERR_FILENO) == -1) {
+ ReportChildError(exec_control[1]);
+ }
close(read_err[1]);
execvp(path, const_cast<char* const*>(program_arguments));
- // In the case of failure write the errno and the OS error message
- // to the exec control pipe.
- int child_errno = errno;
- char* os_error_message = strerror(errno);
- ASSERT(sizeof(child_errno) == sizeof(errno));
- int bytes_written =
- FDUtils::WriteToBlocking(
- exec_control[1], &child_errno, sizeof(child_errno));
- if (bytes_written == sizeof(child_errno)) {
- FDUtils::WriteToBlocking(
- exec_control[1], os_error_message, strlen(os_error_message) + 1);
- }
- close(exec_control[1]);
- exit(1);
+ ReportChildError(exec_control[1]);
}
// The arguments for the spawned process are not needed any longer.
« no previous file with comments | « runtime/bin/process_linux.cc ('k') | runtime/bin/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698