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

Unified Diff: runtime/bin/main.cc

Issue 1275353005: VM thread shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
Index: runtime/bin/main.cc
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index 5c36f41abee04c0ac518f95a8328b615e666fe24..daab5541ada1d838cbc1dc6b6d99d6d9e916ae2a 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -108,8 +108,16 @@ static void ErrorExit(int exit_code, const char* format, ...) {
Dart_ExitScope();
Dart_ShutdownIsolate();
- Dart_Cleanup();
+ // Terminate process exit-code handler.
+ Process::TerminateExitCodeHandler();
+
+ char* error = Dart_Cleanup();
+ if (error != NULL) {
+ Log::PrintErr("VM cleanup failed: %s\n", error);
+ free(error);
+ }
+ EventHandler::Stop();
exit(exit_code);
}
@@ -624,6 +632,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
error);
if (isolate == NULL) {
+ delete isolate_data;
return NULL;
}
@@ -688,7 +697,8 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
Platform::SetPackageRoot(package_root);
- DartUtils::SetupIOLibrary(script_uri);
+ result = DartUtils::SetupIOLibrary(script_uri);
+ CHECK_RESULT(result);
// Make the isolate runnable so that it is ready to handle messages.
Dart_ExitScope();
@@ -1029,15 +1039,18 @@ void main(int argc, char** argv) {
}
// Initialize the Dart VM.
- if (!Dart_Initialize(vm_isolate_snapshot_buffer,
- CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
- DartUtils::OpenFile,
- DartUtils::ReadFile,
- DartUtils::WriteFile,
- DartUtils::CloseFile,
- DartUtils::EntropySource)) {
- fprintf(stderr, "%s", "VM initialization failed\n");
+ char* error = Dart_Initialize(vm_isolate_snapshot_buffer,
Ivan Posva 2015/08/17 13:35:51 Shouldn't the API return a const char*?
zra 2015/08/18 06:23:14 free() takes a non-const pointer, so the compiler
+ CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
+ DartUtils::OpenFile,
+ DartUtils::ReadFile,
+ DartUtils::WriteFile,
+ DartUtils::CloseFile,
+ DartUtils::EntropySource);
+ if (error != NULL) {
+ EventHandler::Stop();
+ fprintf(stderr, "VM initialization failed: %s\n", error);
fflush(stderr);
+ free(error);
exit(kErrorExitCode);
}
@@ -1048,7 +1061,6 @@ void main(int argc, char** argv) {
// Call CreateIsolateAndSetup which creates an isolate and loads up
// the specified application script.
- char* error = NULL;
int exit_code = 0;
char* isolate_name = BuildIsolateName(script_name, "main");
Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
@@ -1061,7 +1073,15 @@ void main(int argc, char** argv) {
if (isolate == NULL) {
Log::PrintErr("%s\n", error);
free(error);
+ error = NULL;
delete [] isolate_name;
+ Process::TerminateExitCodeHandler();
+ error = Dart_Cleanup();
Florian Schneider 2015/08/19 09:02:03 Same question as Ivan: Dart::Cleanup() return a c
+ if (error != NULL) {
+ Log::PrintErr("VM cleanup failed: %s\n", error);
+ free(error);
+ }
+ EventHandler::Stop();
exit((exit_code != 0) ? exit_code : kErrorExitCode);
}
delete [] isolate_name;
@@ -1165,7 +1185,13 @@ void main(int argc, char** argv) {
// Terminate process exit-code handler.
Process::TerminateExitCodeHandler();
- Dart_Cleanup();
+ error = Dart_Cleanup();
+ if (error != NULL) {
+ Log::PrintErr("VM cleanup failed: %s\n", error);
+ free(error);
+ }
+
+ EventHandler::Stop();
// Free copied argument strings if converted.
if (argv_converted) {

Powered by Google App Engine
This is Rietveld 408576698