From 9cf4f2c2d8347c9e7843ac4c00854ca0eb386ac1 Mon Sep 17 00:00:00 2001 From: Chaoren Lin Date: Thu, 23 Apr 2015 18:28:04 +0000 Subject: [PATCH] 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 llvm-svn: 235615 --- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index 0de12da..c001713 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -1796,6 +1796,12 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error) 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)) -- 2.7.4