diff --git a/Source/unix/NSStream.m b/Source/unix/NSStream.m index 92f6867ec..f27d16b00 100644 --- a/Source/unix/NSStream.m +++ b/Source/unix/NSStream.m @@ -564,6 +564,7 @@ static void setNonblocking(int fd) socklen_t len = sizeof(error); unsigned i = [_modes count]; + AUTORELEASE(RETAIN(self)); while (i-- > 0) { [_runloop removeStream: self mode: [_modes objectAtIndex: i]]; @@ -977,6 +978,7 @@ static void setNonblocking(int fd) int result; unsigned i = [_modes count]; + AUTORELEASE(RETAIN(self)); while (i-- > 0) { [_runloop removeStream: self mode: [_modes objectAtIndex: i]]; diff --git a/Source/win32/NSStreamWin32.m b/Source/win32/NSStreamWin32.m index decab0391..24662692a 100644 --- a/Source/win32/NSStreamWin32.m +++ b/Source/win32/NSStreamWin32.m @@ -876,6 +876,7 @@ static void setNonblocking(SOCKET fd) - (void) _dispatch { + AUTORELEASE(RETAIN(self)); /* * Windows only permits a single event to be associated with a socket * at any time, but the runloop system only allows an event handle to @@ -1089,6 +1090,8 @@ static void setNonblocking(SOCKET fd) { [self _recordError]; [self _sendEvent: NSStreamEventErrorOccurred]; + CloseHandle(h); + return; } } [self _setLoopID: (void*)h]; @@ -1609,6 +1612,7 @@ static void setNonblocking(SOCKET fd) - (void) _dispatch { + AUTORELEASE(RETAIN(self)); /* * Windows only permits a single event to be associated with a socket * at any time, but the runloop system only allows an event handle to