From 828eb40b377c2b752a12edbe6de22e2e51545e6d Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 14 Aug 2025 07:57:39 -0700 Subject: [PATCH] [ffi/samples] Avoid using mismatched strdup/CoTaskMemFree on Windows. Fixes https://github.com/dart-lang/sdk/issues/61307 TEST=samples/ffi/http on windows Change-Id: Ibc900896ccb0ea1472b4360cfb7b615fc06efd87 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445108 Commit-Queue: Alexander Aprelev Reviewed-by: Liam Appelbe --- samples/ffi/http/lib/fake_http.cc | 4 ++-- samples/ffi/http/lib/http.dart | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/samples/ffi/http/lib/fake_http.cc b/samples/ffi/http/lib/fake_http.cc index 21a29875bd5..63b4f1d3853 100644 --- a/samples/ffi/http/lib/fake_http.cc +++ b/samples/ffi/http/lib/fake_http.cc @@ -34,7 +34,7 @@ Content-Type: text/html; charset=UTF-8 DART_EXPORT void http_get(const char* uri, void (*onResponse)(const char*)) { std::thread([onResponse]() { std::this_thread::sleep_for(std::chrono::seconds(3)); - onResponse(strdup(kExampleResponse)); + onResponse(kExampleResponse); }).detach(); } @@ -42,7 +42,7 @@ DART_EXPORT void http_serve(void (*onRequest)(const char*)) { std::thread([onRequest]() { while (true) { std::this_thread::sleep_for(std::chrono::seconds(1)); - onRequest(strdup(kExampleRequest)); + onRequest(kExampleRequest); } }).detach(); } diff --git a/samples/ffi/http/lib/http.dart b/samples/ffi/http/lib/http.dart index 1fde486f72c..0ce55c2ede4 100644 --- a/samples/ffi/http/lib/http.dart +++ b/samples/ffi/http/lib/http.dart @@ -17,7 +17,6 @@ Future httpGet(String uri) async { final completer = Completer(); void onResponse(Pointer responsePointer) { completer.complete(responsePointer.toDartString()); - calloc.free(responsePointer); } final callback = NativeCallable.listener(onResponse); @@ -44,7 +43,6 @@ void httpServe(void Function(String) onRequest) { // Create the NativeCallable.listener. void onNativeRequest(Pointer requestPointer) { onRequest(requestPointer.toDartString()); - calloc.free(requestPointer); } final callback = NativeCallable.listener(onNativeRequest);