Be more careful to break retain cycles

This commit is contained in:
rfm 2024-12-19 16:51:21 +00:00
parent d5da27bcbc
commit 5a150d8fa2
2 changed files with 15 additions and 13 deletions

View file

@ -431,6 +431,7 @@ typedef struct
this->_delegate = nil; this->_delegate = nil;
[o connection: self didFailWithError: error]; [o connection: self didFailWithError: error];
DESTROY(o); DESTROY(o);
[this->_protocol stopLoading];
DESTROY(this->_protocol); DESTROY(this->_protocol);
} }
@ -511,6 +512,7 @@ typedef struct
this->_delegate = nil; this->_delegate = nil;
[o connectionDidFinishLoading: self]; [o connectionDidFinishLoading: self];
DESTROY(o); DESTROY(o);
[this->_protocol stopLoading];
DESTROY(this->_protocol); DESTROY(this->_protocol);
} }

View file

@ -851,7 +851,7 @@ typedef struct {
if ([methods member: [this->request HTTPMethod]] == nil) if ([methods member: [this->request HTTPMethod]] == nil)
{ {
NSLog(@"Invalid HTTP Method: %@", this->request); NSLog(@"Invalid HTTP Method: %@", this->request);
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self didFailWithError: [this->client URLProtocol: self didFailWithError:
[NSError errorWithDomain: @"Invalid HTTP Method" [NSError errorWithDomain: @"Invalid HTTP Method"
code: 0 code: 0
@ -896,7 +896,7 @@ typedef struct {
e = [NSError errorWithDomain: @"Invalid redirect request" e = [NSError errorWithDomain: @"Invalid redirect request"
code: 0 code: 0
userInfo: nil]; userInfo: nil];
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self [this->client URLProtocol: self
didFailWithError: e]; didFailWithError: e];
} }
@ -959,7 +959,7 @@ typedef struct {
NSLog(@"%@ did not create streams for %@:%@", NSLog(@"%@ did not create streams for %@:%@",
self, host, [url port]); self, host, [url port]);
} }
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self didFailWithError: [this->client URLProtocol: self didFailWithError:
[NSError errorWithDomain: @"can't connect" code: 0 userInfo: [NSError errorWithDomain: @"can't connect" code: 0 userInfo:
[NSDictionary dictionaryWithObjectsAndKeys: [NSDictionary dictionaryWithObjectsAndKeys:
@ -1044,7 +1044,7 @@ typedef struct {
_isLoading = NO; _isLoading = NO;
DESTROY(_writeData); DESTROY(_writeData);
DESTROY(_masked); DESTROY(_masked);
DESTROY(_challenge); DESTROY(_challenge); // break loop where challenge retains us.
DESTROY(_credential); DESTROY(_credential);
if (this->input != nil) if (this->input != nil)
{ {
@ -1085,7 +1085,7 @@ typedef struct {
{ {
NSLog(@"%@ receive error %@", self, e); NSLog(@"%@ receive error %@", self, e);
} }
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self didFailWithError: e]; [this->client URLProtocol: self didFailWithError: e];
} }
return; return;
@ -1116,7 +1116,7 @@ typedef struct {
e = [NSError errorWithDomain: @"parse error" e = [NSError errorWithDomain: @"parse error"
code: 0 code: 0
userInfo: nil]; userInfo: nil];
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self didFailWithError: e]; [this->client URLProtocol: self didFailWithError: e];
return; return;
} }
@ -1226,7 +1226,7 @@ typedef struct {
e = [NSError errorWithDomain: @"Invalid redirect request" e = [NSError errorWithDomain: @"Invalid redirect request"
code: 0 code: 0
userInfo: nil]; userInfo: nil];
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self [this->client URLProtocol: self
didFailWithError: e]; didFailWithError: e];
} }
@ -1388,7 +1388,7 @@ typedef struct {
e = [NSError errorWithDomain: @"Authentication cancelled" e = [NSError errorWithDomain: @"Authentication cancelled"
code: 0 code: 0
userInfo: nil]; userInfo: nil];
[self stopLoading]; [self stopLoading]; // breaks retain loops
[this->client URLProtocol: self [this->client URLProtocol: self
didFailWithError: e]; didFailWithError: e];
} }
@ -1463,7 +1463,7 @@ typedef struct {
r = [this->request mutableCopy]; r = [this->request mutableCopy];
[r setValue: auth [r setValue: auth
forHTTPHeaderField: @"Authorization"]; forHTTPHeaderField: @"Authorization"];
[self stopLoading]; [self stopLoading]; // breaks retain loops
RELEASE(this->request); RELEASE(this->request);
this->request = r; this->request = r;
DESTROY(this->cachedResponse); DESTROY(this->cachedResponse);
@ -1511,7 +1511,7 @@ typedef struct {
*/ */
if (_isLoading == YES) if (_isLoading == YES)
{ {
_isLoading = NO; [self stopLoading]; // Breaks retain loops
[this->client URLProtocolDidFinishLoading: self]; [this->client URLProtocolDidFinishLoading: self];
} }
} }
@ -1549,7 +1549,7 @@ typedef struct {
{ {
NSLog(@"%@ HTTP response not received - %@", self, _parser); NSLog(@"%@ HTTP response not received - %@", self, _parser);
} }
[self stopLoading]; [self stopLoading]; // Breaks retain loops
[this->client URLProtocol: self didFailWithError: [this->client URLProtocol: self didFailWithError:
[NSError errorWithDomain: @"receive incomplete" [NSError errorWithDomain: @"receive incomplete"
code: 0 code: 0
@ -1633,7 +1633,7 @@ typedef struct {
NSLog(@"%@ error reading from HTTPBody stream %@", NSLog(@"%@ error reading from HTTPBody stream %@",
self, [NSError _last]); self, [NSError _last]);
} }
[self stopLoading]; [self stopLoading]; // Breaks retain loops
[this->client URLProtocol: self didFailWithError: [this->client URLProtocol: self didFailWithError:
[NSError errorWithDomain: @"can't read body" [NSError errorWithDomain: @"can't read body"
code: 0 code: 0
@ -1940,7 +1940,7 @@ typedef struct {
{ {
NSError *error = [[[stream streamError] retain] autorelease]; NSError *error = [[[stream streamError] retain] autorelease];
[self stopLoading]; [self stopLoading]; // Breaks retain loops
[this->client URLProtocol: self didFailWithError: error]; [this->client URLProtocol: self didFailWithError: error];
} }
else else