From 70c9742292aa78aa11afb5cf2165f037a8ada997 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 8 Sep 2017 14:33:50 -0700 Subject: [PATCH] Pass ownership of the kernel bytes to the Dart_LoadKernel. (flutter/engine#4078) This is follow-up to https://github.com/dart-lang/sdk/commit/c7faf2dc6b64b65e04d677fa3ad68c1e90e19bff, which made Dart_LoadKernel responsible for the bytes. --- engine/src/flutter/runtime/dart_controller.cc | 11 ++++------- engine/src/flutter/runtime/dart_controller.h | 4 ---- 2 files changed, 4 insertions(+), 11 deletions(-) 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.