From caf14ff364e257e122d5c486fdd21439469360a8 Mon Sep 17 00:00:00 2001 From: Stanislav Baranov Date: Thu, 26 Jul 2018 16:08:12 -0700 Subject: [PATCH] Fix compilation trace memory management problem This fixes issue with compilation trace buffer getting released upon return from VM code to Dart code, before it gets change to save to a file in natives.dart saveCompilationTrace(). --- engine/src/flutter/lib/ui/dart_runtime_hooks.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc index 7c699fda3e..4b8cd18ef4 100644 --- a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc +++ b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc @@ -214,12 +214,23 @@ void SaveCompilationTrace(Dart_NativeArguments args) { return; } - result = Dart_NewExternalTypedData(Dart_TypedData_kUint8, buffer, length); + result = Dart_NewTypedData(Dart_TypedData_kUint8, length); if (Dart_IsError(result)) { Dart_SetReturnValue(args, result); return; } + Dart_TypedData_Type type; + void* data = nullptr; + intptr_t size = 0; + Dart_Handle status = Dart_TypedDataAcquireData(result, &type, &data, &size); + if (Dart_IsError(status)) { + Dart_SetReturnValue(args, status); + return; + } + + memcpy(data, buffer, length); + Dart_TypedDataReleaseData(result); Dart_SetReturnValue(args, result); }