Author: rfm Date: Tue Jul 26 11:56:22 2016 New Revision: 40034 URL: http://svn.gna.org/viewcvs/gnustep?rev=40034&view=rev Log: Fixups for file descriptor leak
Modified: libs/base/trunk/ChangeLog libs/base/trunk/Source/GSSocketStream.m libs/base/trunk/Source/GSStream.m Modified: libs/base/trunk/ChangeLog URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=40034&r1=40033&r2=40034&view=diff ============================================================================== --- libs/base/trunk/ChangeLog (original) +++ libs/base/trunk/ChangeLog Tue Jul 26 11:56:22 2016 @@ -1,3 +1,12 @@ +2016-07-26 Richard Frith-Macdonald <r...@gnu.org> + + * Source/GSStream.m: + * Source/GSSocketStream.m: + In -close we should close the underlying file descriptor (even if the + stream has not formally been opened yet) to ensure we don't leak it. + In -dealloc, if the file descriptor still exists, we should call the + -close method. + 2016-07-26 Richard Frith-Macdonald <r...@gnu.org> * Source/Additions/NSObject+GNUstepbase.m: use separate lock to Modified: libs/base/trunk/Source/GSSocketStream.m URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSSocketStream.m?rev=40034&r1=40033&r2=40034&view=diff ============================================================================== --- libs/base/trunk/Source/GSSocketStream.m (original) +++ libs/base/trunk/Source/GSSocketStream.m Tue Jul 26 11:56:22 2016 @@ -1447,7 +1447,7 @@ - (void) dealloc { - if ([self _isOpened]) + if (_sock != INVALID_SOCKET) { [self close]; } @@ -1821,17 +1821,24 @@ - (void) close { - if (_currentStatus == NSStreamStatusNotOpen) - { - NSDebugMLLog(@"NSStream", - @"Attempt to close unopened stream %@", self); - return; - } - if (_currentStatus == NSStreamStatusClosed) - { - NSDebugMLLog(@"NSStream", - @"Attempt to close already closed stream %@", self); - return; + /* If the socket descriptor is still present, we need to close it to + * avoid a leak no matter what the nominal state of the stream is. + * The descriptor is created before the stream is formally opened. + */ + if (INVALID_SOCKET == _sock) + { + if (_currentStatus == NSStreamStatusNotOpen) + { + NSDebugMLLog(@"NSStream", + @"Attempt to close unopened stream %@", self); + return; + } + if (_currentStatus == NSStreamStatusClosed) + { + NSDebugMLLog(@"NSStream", + @"Attempt to close already closed stream %@", self); + return; + } } [_handler bye]; #if defined(_WIN32) @@ -2311,17 +2318,24 @@ - (void) close { - if (_currentStatus == NSStreamStatusNotOpen) - { - NSDebugMLLog(@"NSStream", - @"Attempt to close unopened stream %@", self); - return; - } - if (_currentStatus == NSStreamStatusClosed) - { - NSDebugMLLog(@"NSStream", - @"Attempt to close already closed stream %@", self); - return; + /* If the socket descriptor is still present, we need to close it to + * avoid a leak no matter what the nominal state of the stream is. + * The descriptor is created before the stream is formally opened. + */ + if (INVALID_SOCKET == _sock) + { + if (_currentStatus == NSStreamStatusNotOpen) + { + NSDebugMLLog(@"NSStream", + @"Attempt to close unopened stream %@", self); + return; + } + if (_currentStatus == NSStreamStatusClosed) + { + NSDebugMLLog(@"NSStream", + @"Attempt to close already closed stream %@", self); + return; + } } [_handler bye]; #if defined(_WIN32) Modified: libs/base/trunk/Source/GSStream.m URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSStream.m?rev=40034&r1=40033&r2=40034&view=diff ============================================================================== --- libs/base/trunk/Source/GSStream.m (original) +++ libs/base/trunk/Source/GSStream.m Tue Jul 26 11:56:22 2016 @@ -720,8 +720,11 @@ - (void) dealloc { - if ([self _isOpened]) - [self close]; + if (_currentStatus != NSStreamStatusNotOpen + && _currentStatus != NSStreamStatusClosed) + { + [self close]; + } RELEASE(_data); [super dealloc]; } _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs