diff --git a/ChangeLog b/ChangeLog index 4d9ce3256..ee41da75c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-06-27 Richard Frith-Macdonald + + * Source/NSPipe.m: Fix descriptor leak ... close on dealloc + * Source/NSTask.m: Don't bother to close pipes. + 2003-06-25 Adam Fedor * Tools/gdnc.1.gz: New file (from Martin Brecher). diff --git a/Source/NSPipe.m b/Source/NSPipe.m index 8f4ba0329..9d91281a5 100644 --- a/Source/NSPipe.m +++ b/Source/NSPipe.m @@ -33,9 +33,14 @@ #endif /** - * The NSPipe provides an encapsulation of the UNIX concept of pipe. + *

The NSPipe provides an encapsulation of the UNIX concept of pipe.
* With NSPipe, it is possible to redirect the standard input or * standard output. + *

+ *

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. + *

*/ @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;