diff options
| author | Pavel Labath <labath@google.com> | 2015-02-04 10:36:57 +0000 |
|---|---|---|
| committer | Pavel Labath <labath@google.com> | 2015-02-04 10:36:57 +0000 |
| commit | 493c3a127f64766ddc1bc05a297c2c53052bee62 (patch) | |
| tree | 804d71450e724d1bd286967866d36f7766c01b6e /lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp | |
| parent | 2a5c0a51ce5b1516b5007aace25a58d8e3c94425 (diff) | |
| download | bcm5719-llvm-493c3a127f64766ddc1bc05a297c2c53052bee62.tar.gz bcm5719-llvm-493c3a127f64766ddc1bc05a297c2c53052bee62.zip | |
Avoid leakage of file descriptors in LLDB and LLGS
Summary:
Both LLDB and LLGS are leaking file descriptors into the debugged process. This plugs the leak by
closing the unneeded descriptors. In one case I use O_CLOEXEC, which I hope is supported on
relevant platforms. I also added a regression test and plugged a fd leak in dosep.py.
Reviewers: vharron, clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D7372
llvm-svn: 228130
Diffstat (limited to 'lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp')
| -rw-r--r-- | lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp index 43a19422d82..e87e6626852 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -1356,6 +1356,11 @@ ProcessMonitor::Launch(LaunchArgs *args) if (PTRACE(PTRACE_TRACEME, 0, NULL, NULL, 0) < 0) exit(ePtraceFailed); + // terminal has already dupped the tty descriptors to stdin/out/err. + // This closes original fd from which they were copied (and avoids + // leaking descriptors to the debugged process. + terminal.CloseSlaveFileDescriptor(); + // Do not inherit setgid powers. if (setgid(getgid()) != 0) exit(eSetGidFailed); @@ -2319,7 +2324,10 @@ ProcessMonitor::DupDescriptor(const char *path, int fd, int flags) if (target_fd == -1) return false; - return (dup2(target_fd, fd) == -1) ? false : true; + if (dup2(target_fd, fd) == -1) + return false; + + return (close(target_fd) == -1) ? false : true; } void |

