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

Unified Diff: runtime/bin/process_linux.cc

Issue 15980006: Fix for leaking file descriptor issue (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_linux.cc
diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc
index 838dc27a75b7aa23aff65aa67dddc2992a2468c6..6f989c4031421a5c339f0553f4994d7f50e95321 100644
--- a/runtime/bin/process_linux.cc
+++ b/runtime/bin/process_linux.cc
@@ -478,26 +478,6 @@ int Process::Start(const char* path,
delete[] program_arguments;
delete[] program_environment;
- int event_fds[2];
- result = TEMP_FAILURE_RETRY(pipe(event_fds));
- if (result < 0) {
- SetChildOsErrorMessage(os_error_message);
- TEMP_FAILURE_RETRY(close(read_in[0]));
- TEMP_FAILURE_RETRY(close(read_in[1]));
- TEMP_FAILURE_RETRY(close(read_err[0]));
- TEMP_FAILURE_RETRY(close(read_err[1]));
- TEMP_FAILURE_RETRY(close(write_out[0]));
- TEMP_FAILURE_RETRY(close(write_out[1]));
- Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
- return errno;
- }
- FDUtils::SetCloseOnExec(event_fds[0]);
- FDUtils::SetCloseOnExec(event_fds[1]);
-
- ProcessInfoList::AddProcess(pid, event_fds[1]);
- *exit_event = event_fds[0];
- FDUtils::SetNonBlocking(event_fds[0]);
-
// Notify child process to start.
char msg = '1';
result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg));
@@ -551,6 +531,28 @@ int Process::Start(const char* path,
*err = read_err[0];
TEMP_FAILURE_RETRY(close(read_err[1]));
+ // Everything went well, so we can listen for the exitcode of our child
+ // process.
+ int event_fds[2];
+ result = TEMP_FAILURE_RETRY(pipe(event_fds));
+ if (result < 0) {
+ SetChildOsErrorMessage(os_error_message);
+ TEMP_FAILURE_RETRY(close(read_in[0]));
+ TEMP_FAILURE_RETRY(close(read_in[1]));
+ TEMP_FAILURE_RETRY(close(read_err[0]));
+ TEMP_FAILURE_RETRY(close(read_err[1]));
+ TEMP_FAILURE_RETRY(close(write_out[0]));
+ TEMP_FAILURE_RETRY(close(write_out[1]));
+ Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
+ return errno;
+ }
+ FDUtils::SetCloseOnExec(event_fds[0]);
+ FDUtils::SetCloseOnExec(event_fds[1]);
+
+ ProcessInfoList::AddProcess(pid, event_fds[1]);
+ *exit_event = event_fds[0];
+ FDUtils::SetNonBlocking(event_fds[0]);
+
*id = pid;
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698