diff --git a/engine/src/flutter/runtime/dart_controller.cc b/engine/src/flutter/runtime/dart_controller.cc index 5a4ee9d8f3..452f4c5148 100644 --- a/engine/src/flutter/runtime/dart_controller.cc +++ b/engine/src/flutter/runtime/dart_controller.cc @@ -45,7 +45,7 @@ std::string ResolvePath(std::string path) { } // namespace DartController::DartController() : ui_dart_state_(nullptr), - kernel_bytes(nullptr), platform_kernel_bytes(nullptr) {} + platform_kernel_bytes(nullptr) {} DartController::~DartController() { if (ui_dart_state_) { @@ -56,9 +56,6 @@ DartController::~DartController() { Dart_ShutdownIsolate(); // deletes ui_dart_state_ ui_dart_state_ = nullptr; } - if (kernel_bytes) { - free(kernel_bytes); - } if (platform_kernel_bytes) { free(platform_kernel_bytes); } @@ -113,9 +110,9 @@ static void CopyVectorBytes(const std::vector& vector, tonic::DartErrorHandleType DartController::RunFromKernel( const std::vector& kernel) { tonic::DartState::Scope scope(dart_state()); - // Copy kernel bytes so they won't go away after we exit this method. - // This is needed because original kernel data has to be available - // during code execution. + // Copy kernel bytes and pass ownership of the copy to the Dart_LoadKernel, + // which is expected to release them. + uint8_t* kernel_bytes = nullptr; CopyVectorBytes(kernel, kernel_bytes); Dart_Handle result = Dart_LoadKernel( diff --git a/engine/src/flutter/runtime/dart_controller.h b/engine/src/flutter/runtime/dart_controller.h index 5984997478..05a9cb877c 100644 --- a/engine/src/flutter/runtime/dart_controller.h +++ b/engine/src/flutter/runtime/dart_controller.h @@ -42,10 +42,6 @@ class DartController { // during isolate shutdown. UIDartState* ui_dart_state_; - // Kernel binary image of dart script. This is copied and maintained - // for dart script lifespan, so that kernel loading mechanism can - // incrementally build the dart objects from it. - uint8_t* kernel_bytes; // Kernel binary image of platform core libraries. This is copied and // maintained for dart script lifespan, so that kernel loading mechanism can // incrementally build the dart objects from it.