Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 893a479

Browse files
author
sandra
committedJul 26, 2012
2012-07-26 Kazu Hirata <[email protected]>
Sandra Loosemore <[email protected]> libiberty/ * pex-win32.c (pex_win32_exec_child): Only close original file descriptors if child is launched successfully. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@189901 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 4a1f6fe commit 893a479

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed
 

‎libiberty/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2012-07-26 Kazu Hirata <kazu@codesourcery.com>
2+
Sandra Loosemore <sandra@codesourcery.com>
3+
4+
* pex-win32.c (pex_win32_exec_child): Only close original file
5+
descriptors if child is launched successfully.
6+
17
2012-07-18 Jason Merrill <jason@redhat.com>
28

39
* cp-demangle.c (cplus_demangle_operators): Add *_cast.

‎libiberty/pex-win32.c

+17-8
Original file line numberDiff line numberDiff line change
@@ -741,24 +741,17 @@ pex_win32_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED, int flags,
741741
int orig_out, orig_in, orig_err;
742742
BOOL separate_stderr = !(flags & PEX_STDERR_TO_STDOUT);
743743

744-
/* Ensure we have inheritable descriptors to pass to the child, and close the
745-
original descriptors. */
744+
/* Ensure we have inheritable descriptors to pass to the child. */
746745
orig_in = in;
747746
in = _dup (orig_in);
748-
if (orig_in != STDIN_FILENO)
749-
_close (orig_in);
750747

751748
orig_out = out;
752749
out = _dup (orig_out);
753-
if (orig_out != STDOUT_FILENO)
754-
_close (orig_out);
755750

756751
if (separate_stderr)
757752
{
758753
orig_err = errdes;
759754
errdes = _dup (orig_err);
760-
if (orig_err != STDERR_FILENO)
761-
_close (orig_err);
762755
}
763756

764757
stdin_handle = INVALID_HANDLE_VALUE;
@@ -836,6 +829,22 @@ pex_win32_exec_child (struct pex_obj *obj ATTRIBUTE_UNUSED, int flags,
836829
*errmsg = "CreateProcess";
837830
}
838831

832+
/* If the child was created successfully, close the original file
833+
descriptors. If the process creation fails, these are closed by
834+
pex_run_in_environment instead. We must not close them twice as
835+
that seems to cause a Windows exception. */
836+
837+
if (pid != (pid_t) -1)
838+
{
839+
if (orig_in != STDIN_FILENO)
840+
_close (orig_in);
841+
if (orig_out != STDOUT_FILENO)
842+
_close (orig_out);
843+
if (separate_stderr
844+
&& orig_err != STDERR_FILENO)
845+
_close (orig_err);
846+
}
847+
839848
/* Close the standard input, standard output and standard error handles
840849
in the parent. */
841850

0 commit comments

Comments
 (0)
Failed to load comments.