From 676a044f5d415d7bc5b52b5e4eb6bc0294cc1c9a Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 4 Feb 2009 10:44:18 +0000 Subject: [PATCH] Add some diagnostics and ensure that delegates are removed from streams. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27777 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 ++++ Source/NSURLProtocol.m | 67 +++++++++++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 36cdb3545..04451125c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-02-04 Richard Frith-Macdonald + + * Source/NSURLProtocol.m: Add some diagnostics and ensure that + delegates are removed from streams. + 2009-02-04 David Chisnall * Source/GSArray.m: Firther fast enumeration bugfixes. diff --git a/Source/NSURLProtocol.m b/Source/NSURLProtocol.m index ac863d2bf..35d3ab2ac 100644 --- a/Source/NSURLProtocol.m +++ b/Source/NSURLProtocol.m @@ -364,10 +364,21 @@ static NSURLProtocol *placeholder = nil; if (this != 0) { [self stopLoading]; - RELEASE(this->input); - RELEASE(this->output); - RELEASE(this->cachedResponse); - RELEASE(this->request); + if (this->input != nil) + { + [this->input setDelegate: nil]; + [this->output setDelegate: nil]; + [this->input removeFromRunLoop: [NSRunLoop currentRunLoop] + forMode: NSDefaultRunLoopMode]; + [this->output removeFromRunLoop: [NSRunLoop currentRunLoop] + forMode: NSDefaultRunLoopMode]; + [this->input close]; + [this->output close]; + DESTROY(this->input); + DESTROY(this->output); + } + DESTROY(this->cachedResponse); + DESTROY(this->request); #if USE_ZLIB if (this->compressing == YES) { @@ -377,7 +388,7 @@ static NSURLProtocol *placeholder = nil; { inflateEnd(&this->z); } - RELEASE(this->compressed); + DESTROY(this->compressed); #endif NSZoneFree([self zone], this); _NSURLProtocolInternal = 0; @@ -701,6 +712,8 @@ static NSURLProtocol *placeholder = nil; DESTROY(_writeData); if (this->input != nil) { + [this->input setDelegate: nil]; + [this->output setDelegate: nil]; [self _unschedule]; [this->input close]; [this->output close]; @@ -1074,6 +1087,8 @@ static NSURLProtocol *placeholder = nil; [self _unschedule]; if (_shouldClose == YES) { + [this->input setDelegate: nil]; + [this->output setDelegate: nil]; [this->input close]; [this->output close]; DESTROY(this->input); @@ -1391,9 +1406,23 @@ static NSURLProtocol *placeholder = nil; break; } } - NSLog(@"An error %@ occurred on the event %08x of stream %@ of %@", [stream streamError], event, stream, self); - [self stopLoading]; - [this->client URLProtocol: self didFailWithError: [stream streamError]]; + else + { + NSLog(@"Unexpected event %d occurred on stream %@ not being used by %@", + event, stream, self); + } + if (event == NSStreamEventErrorOccurred) + { + NSLog(@"An error %@ occurred on stream %@ of %@", + [stream streamError], stream, self); + [self stopLoading]; + [this->client URLProtocol: self didFailWithError: [stream streamError]]; + } + else + { + NSLog(@"Unexpected event %d ignored on stream %@ of %@", + event, stream, self); + } } - (void) useCredential: (NSURLCredential*)credential @@ -1480,6 +1509,8 @@ static NSURLProtocol *placeholder = nil; { if (this->input) { + [this->input setDelegate: nil]; + [this->output setDelegate: nil]; [this->input removeFromRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode]; [this->output removeFromRunLoop: [NSRunLoop currentRunLoop] @@ -1521,9 +1552,23 @@ static NSURLProtocol *placeholder = nil; NSLog(@"An event occurred on the output stream."); // if successfully opened, send out FTP request header } - NSLog(@"An error %@ occurred on the event %08x of stream %@ of %@", - [stream streamError], event, stream, self); - [this->client URLProtocol: self didFailWithError: [stream streamError]]; + else + { + NSLog(@"Unexpected event %d occurred on stream %@ not being used by %@", + event, stream, self); + } + if (event == NSStreamEventErrorOccurred) + { + NSLog(@"An error %@ occurred on stream %@ of %@", + [stream streamError], stream, self); + [self stopLoading]; + [this->client URLProtocol: self didFailWithError: [stream streamError]]; + } + else + { + NSLog(@"Unexpected event %d ignored on stream %@ of %@", + event, stream, self); + } } @end