[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 <aam@google.com> Reviewed-by: Liam Appelbe <liama@google.com>
This commit is contained in:
committed by
Commit Queue
parent
e805725d17
commit
828eb40b37
@@ -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();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ Future<String> httpGet(String uri) async {
|
||||
final completer = Completer<String>();
|
||||
void onResponse(Pointer<Utf8> responsePointer) {
|
||||
completer.complete(responsePointer.toDartString());
|
||||
calloc.free(responsePointer);
|
||||
}
|
||||
|
||||
final callback = NativeCallable<HttpCallback>.listener(onResponse);
|
||||
@@ -44,7 +43,6 @@ void httpServe(void Function(String) onRequest) {
|
||||
// Create the NativeCallable.listener.
|
||||
void onNativeRequest(Pointer<Utf8> requestPointer) {
|
||||
onRequest(requestPointer.toDartString());
|
||||
calloc.free(requestPointer);
|
||||
}
|
||||
|
||||
final callback = NativeCallable<HttpCallback>.listener(onNativeRequest);
|
||||
|
||||
Reference in New Issue
Block a user