[elbe-devel] [PATCH] elbepack: elbeproject: fix two resource leaks in pdebuild_build()

Thomas Weißschuh thomas.weissschuh at linutronix.de
Thu Jul 25 09:49:54 CEST 2024


Stop leaking open filehandles.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/elbeproject.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index e126098beb42..aad9a2f8d1c7 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -747,11 +747,11 @@ class ElbeProject:
         formatfile = ''
 
         if os.path.exists(os.path.join(pdebuilder_current, 'debian', 'source', 'format')):
-            formatfile = open(os.path.join(pdebuilder_current,
-                              'debian', 'source', 'format'), 'r').read()
+            with open(os.path.join(pdebuilder_current, 'debian', 'source', 'format'), 'r') as f:
+                formatfile = f.read()
 
-        src_pkg_name = open(os.path.join(pdebuilder_current,
-                            'debian', 'changelog'), 'r').readline().split()[0]
+        with open(os.path.join(pdebuilder_current, 'debian', 'changelog'), 'r') as f:
+            src_pkg_name = f.readline().split()[0]
 
         if '3.0 (quilt)' in formatfile and not self.orig_files:
             do(['origtargz', '--download-only', '--tar-only'], cwd=pdebuilder_current)

---
base-commit: 6085e245520afc3b98edcdc03349b44e47d455b3
change-id: 20240725-pbuilder-resource_leak-8753d40eba5d

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list