Skip to content

Commit 2039fb3

Browse files
authored
Fix a reference count race with forwarded delegates. (#888)
1 parent 805a147 commit 2039fb3

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pkgs/cupertino_http/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 0.1.2-dev
1+
## 0.1.2
22

33
* Require Dart 2.19
4+
* Fix a [reference count race with forwarded delegates](https://github.com/dart-lang/http/issues/887).
45

56
## 0.1.1
67

pkgs/cupertino_http/lib/src/cupertino_api.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,9 @@ void _setupDelegation(
827827
final messageType = message[0];
828828
final dp = Pointer<ncb.ObjCObject>.fromAddress(message[1] as int);
829829

830-
final forwardedDelegate =
831-
ncb.CUPHTTPForwardedDelegate.castFromPointer(helperLibs, dp,
832-
// `CUPHTTPForwardedDelegate` was retained in the delegate so it
833-
// only needs to be released.
834-
release: true);
830+
final forwardedDelegate = ncb.CUPHTTPForwardedDelegate.castFromPointer(
831+
helperLibs, dp,
832+
retain: true, release: true);
835833

836834
switch (messageType) {
837835
case ncb.MessageType.RedirectMessage:

pkgs/cupertino_http/src/CUPHTTPClientDelegate.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ - (void)URLSession:(NSURLSession *)session
9191
[forwardedRedirect.lock lock];
9292

9393
completionHandler(forwardedRedirect.redirectRequest);
94+
[forwardedRedirect release];
9495
}
9596

9697
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task
@@ -124,8 +125,8 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task
124125
//
125126
// See the @interface description for CUPHTTPRedirect.
126127
[forwardedResponse.lock lock];
127-
128128
completionHandler(forwardedResponse.disposition);
129+
[forwardedResponse release];
129130
}
130131

131132

@@ -156,6 +157,7 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task
156157
//
157158
// See the @interface description for CUPHTTPRedirect.
158159
[forwardedData.lock lock];
160+
[forwardedData release];
159161
}
160162

161163
- (void)URLSession:(NSURLSession *)session
@@ -183,6 +185,7 @@ - (void)URLSession:(NSURLSession *)session
183185
NSAssert(success, @"Dart_PostCObject_DL failed.");
184186

185187
[forwardedFinishedDownload.lock lock];
188+
[forwardedFinishedDownload release];
186189
}
187190

188191
- (void)URLSession:(NSURLSession *)session
@@ -213,6 +216,7 @@ - (void)URLSession:(NSURLSession *)session
213216
//
214217
// See the @interface description for CUPHTTPRedirect.
215218
[forwardedComplete.lock lock];
219+
[forwardedComplete release];
216220
}
217221

218222
@end

0 commit comments

Comments
 (0)