From fd259d43774431ba0d703ee4b49abfd8a31fa4d0 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 11 Jan 2021 23:25:28 +0000 Subject: [PATCH] [ VM ] Fix invalid free introduced in c42c76f5904c29921591cae815c5e7d53fabc2cf It's possible for loading the CLI isolate from snapshot to be skipped without failing for SIMARM, so *error would not point to a valid error, causing free(*error) to crash. TEST=Existing tests Change-Id: Ic178f7bd0f89c4440b2daf714fbb2e428867bd72 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178723 Reviewed-by: Ben Konyi --- runtime/bin/main.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc index cdffae9fc78..ca8e95e83cd 100644 --- a/runtime/bin/main.cc +++ b/runtime/bin/main.cc @@ -592,7 +592,10 @@ static Dart_Isolate CreateAndSetupDartDevIsolate(const char* script_uri, IsolateGroupData* isolate_group_data = nullptr; IsolateData* isolate_data = nullptr; - AppSnapshot* app_snapshot; + if (error != nullptr) { + *error = nullptr; + } + AppSnapshot* app_snapshot = nullptr; bool isolate_run_app_snapshot = true; if (dartdev_path.get() != nullptr && (app_snapshot = Snapshot::TryReadAppSnapshot(dartdev_path.get())) != @@ -618,8 +621,10 @@ static Dart_Isolate CreateAndSetupDartDevIsolate(const char* script_uri, isolate_run_app_snapshot = false; dartdev_path = DartDevIsolate::TryResolveDartDevKernelPath(); // Clear error from app snapshot and retry from kernel. - free(*error); - *error = nullptr; + if (*error != nullptr) { + free(*error); + *error = nullptr; + } if (app_snapshot != nullptr) { delete app_snapshot;