summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process
diff options
context:
space:
mode:
authorEd Maste <emaste@freebsd.org>2015-02-05 16:09:03 +0000
committerEd Maste <emaste@freebsd.org>2015-02-05 16:09:03 +0000
commit7f0230fad9ea6bfd431aeb0424e7eafedb8720d2 (patch)
treeb3e49216f680d5ff95c85c0d942b77061d7476b4 /lldb/source/Plugins/Process
parentec13f825a6342739577008eb1077945b427f97dd (diff)
downloadbcm5719-llvm-7f0230fad9ea6bfd431aeb0424e7eafedb8720d2.tar.gz
bcm5719-llvm-7f0230fad9ea6bfd431aeb0424e7eafedb8720d2.zip
Avoid leakage of file descriptors in LLDB (apply r228130 to FreeBSD)
llvm-svn: 228305
Diffstat (limited to 'lldb/source/Plugins/Process')
-rw-r--r--lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index e45a0d8655b..d78d7509035 100644
--- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -994,6 +994,11 @@ ProcessMonitor::Launch(LaunchArgs *args)
if (PTRACE(PT_TRACE_ME, 0, 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);
@@ -1558,7 +1563,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
OpenPOWER on IntegriCloud