[Lldb-commits] [lldb] r235615 - Fix TestFdLeak on Linux.

Chaoren Lin chaorenl at google.com
Thu Apr 23 11:28:04 PDT 2015


Author: chaoren
Date: Thu Apr 23 13:28:04 2015
New Revision: 235615

URL: http://llvm.org/viewvc/llvm-project?rev=235615&view=rev
Log:
Fix TestFdLeak on Linux.

Summary:
LLGS leaks pipes (when launched by lldb), sockets (when launched by platform),
and/or log file to the inferior. This should prevent all possible leaks.

Reviewers: vharron, clayborg

Reviewed By: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D9211

Modified:
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=235615&r1=235614&r2=235615&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Thu Apr 23 13:28:04 2015
@@ -1796,6 +1796,12 @@ NativeProcessLinux::Launch(LaunchArgs *a
             if (!DupDescriptor(args->m_stderr_path.c_str (), STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
                 exit(eDupStderrFailed);
 
+        // Close everything besides stdin, stdout, and stderr that has no file
+        // action to avoid leaking
+        for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd)
+            if (!args->m_launch_info.GetFileActionForFD(fd))
+                close(fd);
+
         // Change working directory
         if (working_dir != NULL && working_dir[0])
           if (0 != ::chdir(working_dir))





More information about the lldb-commits mailing list