[Lldb-commits] [lldb] r228305 - Avoid leakage of file descriptors in LLDB (apply r228130 to FreeBSD)

Ed Maste emaste at freebsd.org
Thu Feb 5 08:09:03 PST 2015


Author: emaste
Date: Thu Feb  5 10:09:03 2015
New Revision: 228305

URL: http://llvm.org/viewvc/llvm-project?rev=228305&view=rev
Log:
Avoid leakage of file descriptors in LLDB (apply r228130 to FreeBSD)

Modified:
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=228305&r1=228304&r2=228305&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Thu Feb  5 10:09:03 2015
@@ -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
     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





More information about the lldb-commits mailing list