mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fixups for file descriptor leak
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@40034 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
205f26ec86
commit
525d467e18
3 changed files with 49 additions and 23 deletions
|
@ -1,3 +1,12 @@
|
|||
2016-07-26 Richard Frith-Macdonald <rfm@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 <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/NSObject+GNUstepbase.m: use separate lock to
|
||||
|
|
|
@ -1447,7 +1447,7 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
if ([self _isOpened])
|
||||
if (_sock != INVALID_SOCKET)
|
||||
{
|
||||
[self close];
|
||||
}
|
||||
|
@ -1821,17 +1821,24 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (void) close
|
||||
{
|
||||
if (_currentStatus == NSStreamStatusNotOpen)
|
||||
/* 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)
|
||||
{
|
||||
NSDebugMLLog(@"NSStream",
|
||||
@"Attempt to close unopened stream %@", self);
|
||||
return;
|
||||
}
|
||||
if (_currentStatus == NSStreamStatusClosed)
|
||||
{
|
||||
NSDebugMLLog(@"NSStream",
|
||||
@"Attempt to close already closed stream %@", self);
|
||||
return;
|
||||
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 @@ setNonBlocking(SOCKET fd)
|
|||
|
||||
- (void) close
|
||||
{
|
||||
if (_currentStatus == NSStreamStatusNotOpen)
|
||||
/* 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)
|
||||
{
|
||||
NSDebugMLLog(@"NSStream",
|
||||
@"Attempt to close unopened stream %@", self);
|
||||
return;
|
||||
}
|
||||
if (_currentStatus == NSStreamStatusClosed)
|
||||
{
|
||||
NSDebugMLLog(@"NSStream",
|
||||
@"Attempt to close already closed stream %@", self);
|
||||
return;
|
||||
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)
|
||||
|
|
|
@ -720,8 +720,11 @@ static RunLoopEventType typeForStream(NSStream *aStream)
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
if ([self _isOpened])
|
||||
[self close];
|
||||
if (_currentStatus != NSStreamStatusNotOpen
|
||||
&& _currentStatus != NSStreamStatusClosed)
|
||||
{
|
||||
[self close];
|
||||
}
|
||||
RELEASE(_data);
|
||||
[super dealloc];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue