summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-03-13 14:45:06 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-03-13 14:45:06 +0000
commit82d55239eae14af084fb35f7692d463b5834fb6d (patch)
treef2b3f77113accdc110c1d78038896f888f09423f /llvm/lib/Support
parent7d21a3d2c3ffc24c68eed2d3f3e1843d1bb66a7d (diff)
downloadbcm5719-llvm-82d55239eae14af084fb35f7692d463b5834fb6d.tar.gz
bcm5719-llvm-82d55239eae14af084fb35f7692d463b5834fb6d.zip
Fix crash when multiple raw_fd_ostreams to stdout are created.
If raw_fd_ostream is constructed with the path of "-", it claims ownership of the stdout file descriptor. This means that it closes stdout when it is destroyed. If there are multiple users of raw_fd_ostream wrapped around stdout, then a crash can occur because of operations on a closed stream. An example of this would be running something like "clang -S -o - -MD -MF - test.cpp". Alternatively, using outs() (which creates a local version of raw_fd_stream to stdout) anywhere combined with such a stream usage would cause the crash. The fix duplicates the stdout file descriptor when used within raw_fd_ostream, so that only that particular descriptor is closed when the stream is destroyed. Patch by James Henderson! llvm-svn: 297624
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index d073802db93..5deab5de4f6 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -473,7 +473,7 @@ static int getFD(StringRef Filename, std::error_code &EC,
// possible.
if (!(Flags & sys::fs::F_Text))
sys::ChangeStdoutToBinary();
- return STDOUT_FILENO;
+ return dup(STDOUT_FILENO);
}
int FD;
OpenPOWER on IntegriCloud