mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix descriptor leak
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17047 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7f464aeb38
commit
9b176a1e62
2 changed files with 25 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
2003-06-27 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSPipe.m: Fix descriptor leak ... close on dealloc
|
||||
* Source/NSTask.m: Don't bother to close pipes.
|
||||
|
||||
2003-06-25 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Tools/gdnc.1.gz: New file (from Martin Brecher).
|
||||
|
|
|
@ -33,9 +33,14 @@
|
|||
#endif
|
||||
|
||||
/**
|
||||
* The NSPipe provides an encapsulation of the UNIX concept of pipe.
|
||||
* <p>The NSPipe provides an encapsulation of the UNIX concept of pipe.<br />
|
||||
* With NSPipe, it is possible to redirect the standard input or
|
||||
* standard output.
|
||||
* </p>
|
||||
* <p>The file handles created by NSPipe are automatically closed when they
|
||||
* are no longer in use (ie when the NSPipe instance is deallocated), so you
|
||||
* don't need to close them explicitly.
|
||||
* </p>
|
||||
*/
|
||||
@implementation NSPipe
|
||||
|
||||
|
@ -65,8 +70,10 @@
|
|||
|
||||
if (pipe(p) == 0)
|
||||
{
|
||||
readHandle = [[NSFileHandle alloc] initWithFileDescriptor: p[0]];
|
||||
writeHandle = [[NSFileHandle alloc] initWithFileDescriptor: p[1]];
|
||||
readHandle = [[NSFileHandle alloc] initWithFileDescriptor: p[0]
|
||||
closeOnDealloc: YES];
|
||||
writeHandle = [[NSFileHandle alloc] initWithFileDescriptor: p[1]
|
||||
closeOnDealloc: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -78,19 +85,27 @@
|
|||
|
||||
if (CreatePipe(&readh, &writeh, NULL, 0) != 0)
|
||||
{
|
||||
readHandle = [[NSFileHandle alloc] initWithNativeHandle: readh];
|
||||
writeHandle = [[NSFileHandle alloc] initWithNativeHandle: writeh];
|
||||
readHandle = [[NSFileHandle alloc] initWithNativeHandle: readh
|
||||
closeOnDealloc: YES];
|
||||
writeHandle = [[NSFileHandle alloc] initWithNativeHandle: writeh
|
||||
closeOnDealloc: YES];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file handle for reading from the pipe.
|
||||
*/
|
||||
- (id) fileHandleForReading
|
||||
{
|
||||
return readHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file handle for writing to the pipe.
|
||||
*/
|
||||
- (id) fileHandleForWriting
|
||||
{
|
||||
return writeHandle;
|
||||
|
|
Loading…
Reference in a new issue