[Lldb-commits] [PATCH] Fix descriptor leak in multi-target debugging

Zachary Turner zturner at google.com
Mon Feb 9 11:16:54 PST 2015


Hi, please be careful with O_CLOEXEC in the future.  I've had to fix two
patches on Windows in the past week because of it.  It's not the end of the
world, but just keep in mind next time using it that it doesn't exist on
Windows so you'll need to wrap its use in an #if defined(_MSC_VER)

On Mon Feb 09 2015 at 3:41:01 AM Pavel Labath <labath at google.com> wrote:

> REPOSITORY
>   rL LLVM
>
> http://reviews.llvm.org/D7466
>
> Files:
>   lldb/trunk/source/Utility/PseudoTerminal.cpp
>   lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py
>
> Index: lldb/trunk/source/Utility/PseudoTerminal.cpp
> ===================================================================
> --- lldb/trunk/source/Utility/PseudoTerminal.cpp
> +++ lldb/trunk/source/Utility/PseudoTerminal.cpp
> @@ -239,7 +239,7 @@
>          error_str[0] = '\0';
>
>      pid_t pid = LLDB_INVALID_PROCESS_ID;
> -    if (OpenFirstAvailableMaster (O_RDWR, error_str, error_len))
> +    if (OpenFirstAvailableMaster (O_RDWR | O_CLOEXEC, error_str,
> error_len))
>      {
>          // Successfully opened our master pseudo terminal
>
> @@ -258,7 +258,8 @@
>              if (OpenSlave (O_RDWR, error_str, error_len))
>              {
>                  // Successfully opened slave
> -                // We are done with the master in the child process so
> lets close it
> +
> +                // Master FD should have O_CLOEXEC set, but let's close
> it just in case...
>                  CloseMasterFileDescriptor ();
>
>  #if defined(TIOCSCTTY)
> Index: lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py
> ===================================================================
> --- lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py
> +++ lldb/trunk/test/functionalities/avoids-fd-leak/TestFdLeak.py
> @@ -36,6 +36,29 @@
>          self.assertTrue(process.GetExitStatus() == 0,
>                  "Process returned non-zero status. Were incorrect file
> descriptors passed?")
>
> +    @skipIfWindows # The check for descriptor leakage needs to be
> implemented differently here.
> +    def test_fd_leak_multitarget (self):
> +        self.buildDefault()
> +        exe = os.path.join (os.getcwd(), "a.out")
> +
> +        target = self.dbg.CreateTarget(exe)
> +
> +        listener = lldb.SBListener()
> +        error = lldb.SBError()
> +        process1 = target.Launch (listener, None, None, None, None, None,
> +                self.get_process_working_directory(), 0, True, # stop at
> entry
> +                error)
> +        self.assertTrue(process1, PROCESS_IS_VALID)
> +        self.assertTrue(process1.GetState() == lldb.eStateStopped,
> "Process should have been stopped.")
> +
> +        target2 = self.dbg.CreateTarget(exe)
> +        process2 = target2.LaunchSimple (None, None,
> self.get_process_working_directory())
> +        self.assertTrue(process2, PROCESS_IS_VALID)
> +
> +        self.assertTrue(process2.GetState() == lldb.eStateExited,
> "Process should have exited.")
> +        self.assertTrue(process2.GetExitStatus() == 0,
> +                "Process returned non-zero status. Were incorrect file
> descriptors passed?")
> +
>
>  if __name__ == '__main__':
>      import atexit
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150209/b8b144c1/attachment.html>


More information about the lldb-commits mailing list