Skip to content

Commit 828eb40

Browse files
aamCommit Queue
authored andcommitted
[ffi/samples] Avoid using mismatched strdup/CoTaskMemFree on Windows.
Fixes #61307 TEST=samples/ffi/http on windows Change-Id: Ibc900896ccb0ea1472b4360cfb7b615fc06efd87 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445108 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Liam Appelbe <[email protected]>
1 parent e805725 commit 828eb40

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

samples/ffi/http/lib/fake_http.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ Content-Type: text/html; charset=UTF-8
3434
DART_EXPORT void http_get(const char* uri, void (*onResponse)(const char*)) {
3535
std::thread([onResponse]() {
3636
std::this_thread::sleep_for(std::chrono::seconds(3));
37-
onResponse(strdup(kExampleResponse));
37+
onResponse(kExampleResponse);
3838
}).detach();
3939
}
4040

4141
DART_EXPORT void http_serve(void (*onRequest)(const char*)) {
4242
std::thread([onRequest]() {
4343
while (true) {
4444
std::this_thread::sleep_for(std::chrono::seconds(1));
45-
onRequest(strdup(kExampleRequest));
45+
onRequest(kExampleRequest);
4646
}
4747
}).detach();
4848
}

samples/ffi/http/lib/http.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Future<String> httpGet(String uri) async {
1717
final completer = Completer<String>();
1818
void onResponse(Pointer<Utf8> responsePointer) {
1919
completer.complete(responsePointer.toDartString());
20-
calloc.free(responsePointer);
2120
}
2221

2322
final callback = NativeCallable<HttpCallback>.listener(onResponse);
@@ -44,7 +43,6 @@ void httpServe(void Function(String) onRequest) {
4443
// Create the NativeCallable.listener.
4544
void onNativeRequest(Pointer<Utf8> requestPointer) {
4645
onRequest(requestPointer.toDartString());
47-
calloc.free(requestPointer);
4846
}
4947

5048
final callback = NativeCallable<HttpCallback>.listener(onNativeRequest);

0 commit comments

Comments
 (0)