Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e514f0b

Browse files
authored
Ensure that typed data is released within SendPlatformMessage scope. (#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 flutter/flutter#29058
1 parent f2b42d6 commit e514f0b

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/ui/window/window.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ void ReportUnhandledException(Dart_NativeArguments args) {
8484
Dart_Handle SendPlatformMessage(Dart_Handle window,
8585
const std::string& name,
8686
Dart_Handle callback,
87-
const tonic::DartByteData& data) {
87+
Dart_Handle data_handle) {
8888
UIDartState* dart_state = UIDartState::Current();
8989

9090
if (!dart_state->window()) {
91-
// Must release the TypedData buffer before allocating other Dart objects.
92-
data.Release();
9391
return tonic::ToDart(
9492
"Platform messages can only be sent from the main isolate");
9593
}
@@ -100,12 +98,12 @@ Dart_Handle SendPlatformMessage(Dart_Handle window,
10098
tonic::DartPersistentValue(dart_state, callback),
10199
dart_state->GetTaskRunners().GetUITaskRunner());
102100
}
103-
if (Dart_IsNull(data.dart_handle())) {
101+
if (Dart_IsNull(data_handle)) {
104102
dart_state->window()->client()->HandlePlatformMessage(
105103
fml::MakeRefCounted<PlatformMessage>(name, response));
106104
} else {
105+
tonic::DartByteData data(data_handle);
107106
const uint8_t* buffer = static_cast<const uint8_t*>(data.data());
108-
109107
dart_state->window()->client()->HandlePlatformMessage(
110108
fml::MakeRefCounted<PlatformMessage>(
111109
name, std::vector<uint8_t>(buffer, buffer + data.length_in_bytes()),

0 commit comments

Comments
 (0)