소스 검색

A patch from Ted Phelps to fix popen(). Ted writes:
There is a minor bug in the implementation of popen(). In the case
where the file descriptor returned from its call to pipe() is the same
as the file descriptor that it is meant to be (where the dup2() branch
is not taken), the end of the pipe is still closed by close(reading)
even though it shouldn't be.
Thanks Ted!

Eric Andersen 23 년 전
부모
커밋
e26a5970ca
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      libc/stdio/popen.c

+ 1 - 1
libc/stdio/popen.c

@@ -34,8 +34,8 @@ FILE *popen (const char *command, const char *mode)
 		if ((fp = fdopen(pnr, mode)) != NULL) {
 			if ((pid = vfork()) == 0) {	/* vfork -- child */
 				close(pnr);
-				close(reading);
 				if (pr != reading) {
+					close(reading);
 					dup2(pr, reading);
 					close(pr);
 				}