When the input file descriptor of the pipe() is dup2()'d into stdin and stdout it is effectively copied, leaving the original file descriptor open and leaking at the end of these statements. Only the output file descriptor has its ownership transferred to File and will be cleaned up properly.
This should cause the reading end to read EOF and return zero bytes when stdin and stdout is open, rather than remaining open "indefinitely" (barring the whole process being taken down) as there will always be that one file descriptor referencing the input end of the pipe.
When the input file descriptor of the
pipe()
isdup2()
'd intostdin
andstdout
it is effectively copied, leaving the original file descriptor open and leaking at the end of these statements. Only the output file descriptor has its ownership transferred toFile
and will be cleaned up properly.This should cause the reading end to read EOF and return zero bytes when
stdin
andstdout
is open, rather than remaining open "indefinitely" (barring the whole process being taken down) as there will always be that one file descriptor referencing the input end of the pipe.