Remove stream from handler upon deallocation, to avlid handler sending messages to deallocated stream.

This commit is contained in:
Richard Frith-Macdonald 2021-01-16 06:23:25 +00:00
parent fa27dfeed4
commit dca9b65313

View file

@ -288,6 +288,7 @@ GSPrivateSockaddrSetup(NSString *machine, uint16_t port,
- (BOOL) handshake; /* A handshake/hello is in progress. */
- (void) hello; /* Start up the session handshake. */
- (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len;
- (void) remove: (NSStream*)stream; /* Stream no longer available */
- (void) stream: (NSStream*)stream handleEvent: (NSStreamEvent)event;
- (NSInteger) write: (const uint8_t *)buffer maxLength: (NSUInteger)len;
@end
@ -346,6 +347,18 @@ GSPrivateSockaddrSetup(NSString *machine, uint16_t port,
return 0;
}
- (void) remove: (NSStream*)stream
{
if ((id)stream == (id)istream)
{
istream = nil;
}
if ((id)stream == (id)ostream)
{
ostream = nil;
}
}
- (void) stream: (NSStream*)stream handleEvent: (NSStreamEvent)event
{
[self subclassResponsibility: _cmd];
@ -1505,6 +1518,7 @@ setNonBlocking(SOCKET fd)
}
[_sibling _setSibling: nil];
_sibling = nil;
[_handler remove: self];
DESTROY(_handler);
[super dealloc];
}