From 57e1ce6c818a2678e286f2a1498d4c04dd782030 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 14 Mar 2019 12:02:46 -0700 Subject: [PATCH] Ensure that typed data is released within SendPlatformMessage scope. (flutter/engine#8155) We used to make tonic make the wrapper before the SendPlatformMessage invocation. However, tonic would not collect the wrapper before make the Dart API call to return the value from the native method. This is illegal and would trip an assertion in the Dart VM. A more systematic fix required reworking tonic to handle this case. However, to fix our illegal use of the Dart API now, this patch creates the wrapper manually in function scope. Fixes https://github.com/flutter/flutter/issues/29058 --- engine/src/flutter/lib/ui/window/window.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/lib/ui/window/window.cc b/engine/src/flutter/lib/ui/window/window.cc index bfeb86cef6..fb53dda3f1 100644 --- a/engine/src/flutter/lib/ui/window/window.cc +++ b/engine/src/flutter/lib/ui/window/window.cc @@ -84,12 +84,10 @@ void ReportUnhandledException(Dart_NativeArguments args) { Dart_Handle SendPlatformMessage(Dart_Handle window, const std::string& name, Dart_Handle callback, - const tonic::DartByteData& data) { + Dart_Handle data_handle) { UIDartState* dart_state = UIDartState::Current(); if (!dart_state->window()) { - // Must release the TypedData buffer before allocating other Dart objects. - data.Release(); return tonic::ToDart( "Platform messages can only be sent from the main isolate"); } @@ -100,12 +98,12 @@ Dart_Handle SendPlatformMessage(Dart_Handle window, tonic::DartPersistentValue(dart_state, callback), dart_state->GetTaskRunners().GetUITaskRunner()); } - if (Dart_IsNull(data.dart_handle())) { + if (Dart_IsNull(data_handle)) { dart_state->window()->client()->HandlePlatformMessage( fml::MakeRefCounted(name, response)); } else { + tonic::DartByteData data(data_handle); const uint8_t* buffer = static_cast(data.data()); - dart_state->window()->client()->HandlePlatformMessage( fml::MakeRefCounted( name, std::vector(buffer, buffer + data.length_in_bytes()),