Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a reference count race with forwarded delegates. #888

Merged
merged 2 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkgs/cupertino_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 3 additions & 5 deletions pkgs/cupertino_http/lib/src/cupertino_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,9 @@ void _setupDelegation(
final messageType = message[0];
final dp = Pointer<ncb.ObjCObject>.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:
Expand Down
6 changes: 5 additions & 1 deletion pkgs/cupertino_http/src/CUPHTTPClientDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ - (void)URLSession:(NSURLSession *)session
[forwardedRedirect.lock lock];

completionHandler(forwardedRedirect.redirectRequest);
[forwardedRedirect release];
}

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task
Expand Down Expand Up @@ -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];
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -183,6 +185,7 @@ - (void)URLSession:(NSURLSession *)session
NSAssert(success, @"Dart_PostCObject_DL failed.");

[forwardedFinishedDownload.lock lock];
[forwardedFinishedDownload release];
}

- (void)URLSession:(NSURLSession *)session
Expand Down Expand Up @@ -213,6 +216,7 @@ - (void)URLSession:(NSURLSession *)session
//
// See the @interface description for CUPHTTPRedirect.
[forwardedComplete.lock lock];
[forwardedComplete release];
}

@end