From 9036e0aae8fbc367031a79fefc1bdf1a9bdabd79 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Thu, 12 Apr 2007 19:39:23 +0000 Subject: [PATCH] Avoid possibility of stream deallocation while sending events. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25004 72102866-910b-0410-8b05-ffd578937521 --- Source/unix/NSStream.m | 2 ++ Source/win32/NSStreamWin32.m | 4 ++++ 2 files changed, 6 insertions(+) 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