From ef3252c73daa39d993966fe02fded7cf7339a02e Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Wed, 24 Jul 2024 21:58:10 +0000 Subject: [PATCH] fix: gen_snapshot crashes if passed a non-existent file. Closes https://github.com/dart-lang/sdk/pull/56310 GitOrigin-RevId: 9fa800ae9da26369b6a5cafce726ad881187459f Change-Id: Ia8911ab67afb65425ad40d3273436420e0cea0ff Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377303 Commit-Queue: Ryan Macnak Reviewed-by: Ryan Macnak Reviewed-by: Alexander Aprelev --- runtime/bin/gen_snapshot.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc index 08a427cf2fd..c5e7b2eff02 100644 --- a/runtime/bin/gen_snapshot.cc +++ b/runtime/bin/gen_snapshot.cc @@ -316,8 +316,11 @@ PRINTF_ATTRIBUTE(1, 2) static void PrintErrAndExit(const char* format, ...) { Syslog::VPrintErr(format, args); va_end(args); - Dart_ExitScope(); - Dart_ShutdownIsolate(); + // ExitScope and ShutdownIsolate will abort() if there is no current isolate. + if (Dart_CurrentIsolate() != nullptr) { + Dart_ExitScope(); + Dart_ShutdownIsolate(); + } exit(kErrorExitCode); }