From 6c8427501d859ce2ac85b9e90bb895640e48136c Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Wed, 8 Mar 2023 14:40:46 -0800 Subject: [PATCH 1/2] Fix a reference count race with forwarded delegates. --- pkgs/cupertino_http/lib/src/cupertino_api.dart | 8 +++----- pkgs/cupertino_http/src/CUPHTTPClientDelegate.m | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkgs/cupertino_http/lib/src/cupertino_api.dart b/pkgs/cupertino_http/lib/src/cupertino_api.dart index 59d1187803..2157dd9f1f 100644 --- a/pkgs/cupertino_http/lib/src/cupertino_api.dart +++ b/pkgs/cupertino_http/lib/src/cupertino_api.dart @@ -827,11 +827,9 @@ void _setupDelegation( final messageType = message[0]; final dp = Pointer.fromAddress(message[1] as int); - final forwardedDelegate = - ncb.CUPHTTPForwardedDelegate.castFromPointer(helperLibs, dp, - // `CUPHTTPForwardedDelegate` was retained in the delegate so it - // only needs to be released. - release: true); + final forwardedDelegate = ncb.CUPHTTPForwardedDelegate.castFromPointer( + helperLibs, dp, + retain: true, release: true); switch (messageType) { case ncb.MessageType.RedirectMessage: diff --git a/pkgs/cupertino_http/src/CUPHTTPClientDelegate.m b/pkgs/cupertino_http/src/CUPHTTPClientDelegate.m index 2483f6d1ba..a1eff15f9a 100644 --- a/pkgs/cupertino_http/src/CUPHTTPClientDelegate.m +++ b/pkgs/cupertino_http/src/CUPHTTPClientDelegate.m @@ -91,6 +91,7 @@ - (void)URLSession:(NSURLSession *)session [forwardedRedirect.lock lock]; completionHandler(forwardedRedirect.redirectRequest); + [forwardedRedirect release]; } - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task @@ -124,8 +125,8 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task // // See the @interface description for CUPHTTPRedirect. [forwardedResponse.lock lock]; - completionHandler(forwardedResponse.disposition); + [forwardedResponse release]; } @@ -156,6 +157,7 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task // // See the @interface description for CUPHTTPRedirect. [forwardedData.lock lock]; + [forwardedData release]; } - (void)URLSession:(NSURLSession *)session @@ -183,6 +185,7 @@ - (void)URLSession:(NSURLSession *)session NSAssert(success, @"Dart_PostCObject_DL failed."); [forwardedFinishedDownload.lock lock]; + [forwardedFinishedDownload release]; } - (void)URLSession:(NSURLSession *)session @@ -213,6 +216,7 @@ - (void)URLSession:(NSURLSession *)session // // See the @interface description for CUPHTTPRedirect. [forwardedComplete.lock lock]; + [forwardedComplete release]; } @end From 93454f3caba2f513aa967c3e6603c886154e5ee9 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Wed, 8 Mar 2023 18:21:50 -0800 Subject: [PATCH 2/2] Update CHANGELOG.md --- pkgs/cupertino_http/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/cupertino_http/CHANGELOG.md b/pkgs/cupertino_http/CHANGELOG.md index 7029f06917..cc290c28d7 100644 --- a/pkgs/cupertino_http/CHANGELOG.md +++ b/pkgs/cupertino_http/CHANGELOG.md @@ -1,6 +1,7 @@ -## 0.1.2-dev +## 0.1.2 * Require Dart 2.19 +* Fix a [reference count race with forwarded delegates](https://github.com/dart-lang/http/issues/887). ## 0.1.1