[Lldb-commits] [lldb] [lldb] fix fd leak during lldb testsuite (PR #118093)

via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 29 05:42:08 PST 2024


https://github.com/dlav-sc created https://github.com/llvm/llvm-project/pull/118093

During lldb testing dotest.py opens files to dump testcase results, but doesn't close them.

This patch makes neccessary changes to fix the file descriptors leak.

>From e449a10882233c52d9ae8602376489340afdf6e9 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Tue, 12 Nov 2024 14:25:09 +0000
Subject: [PATCH] [lldb] fix fd leak during lldb testsuite

During lldb testing dotest.py opens files to dump testcase results, but
doesn't close them.

This patch makes neccessary changes to fix the file descriptors leak.
---
 .../Python/lldbsuite/test/lldbtest.py         | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 8884ef5933ada8..1338d16a9171e2 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -865,13 +865,9 @@ def setUp(self):
         session_file = self.getLogBasenameForCurrentTest() + ".log"
         self.log_files.append(session_file)
 
-        # Python 3 doesn't support unbuffered I/O in text mode.  Open buffered.
-        self.session = encoded_file.open(session_file, "utf-8", mode="w")
-
         # Optimistically set __errored__, __failed__, __expected__ to False
         # initially.  If the test errored/failed, the session info
-        # (self.session) is then dumped into a session specific file for
-        # diagnosis.
+        # is then dumped into a session specific file for diagnosis.
         self.__cleanup_errored__ = False
         self.__errored__ = False
         self.__failed__ = False
@@ -1235,20 +1231,25 @@ def dumpSessionInfo(self):
         else:
             prefix = "Success"
 
+        session_file = self.getLogBasenameForCurrentTest() + ".log"
+
+        # Python 3 doesn't support unbuffered I/O in text mode.  Open buffered.
+        session = encoded_file.open(session_file, "utf-8", mode="w")
+
         if not self.__unexpected__ and not self.__skipped__:
             for test, traceback in pairs:
                 if test is self:
-                    print(traceback, file=self.session)
+                    print(traceback, file=session)
 
         import datetime
 
         print(
             "Session info generated @",
             datetime.datetime.now().ctime(),
-            file=self.session,
+            file=session,
         )
-        self.session.close()
-        del self.session
+        session.close()
+        del session
 
         # process the log files
         if prefix != "Success" or lldbtest_config.log_success:



More information about the lldb-commits mailing list