samba_version.py: Avoid resource leak
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 20 Feb 2023 22:38:54 +0000 (11:38 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 3 Mar 2023 01:07:36 +0000 (01:07 +0000)
View with 'git show -b'.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/wafsamba/samba_version.py

index 5df7ddbcb3df93ada962a6d6e4ba1a1c176a65f9..54ae62f38bd346acfe73d8f3d18d45db3740de55 100644 (file)
@@ -235,22 +235,22 @@ also accepted as dictionary entries here
 def samba_version_file(version_file, path, env=None, is_install=True):
     '''Parse the version information from a VERSION file'''
 
-    f = open(version_file, 'r')
-    version_dict = {}
-    for line in f:
-        line = line.strip()
-        if line == '':
-            continue
-        if line.startswith("#"):
-            continue
-        try:
-            split_line = line.split("=")
-            if split_line[1] != "":
-                value = split_line[1].strip('"')
-                version_dict[split_line[0]] = value
-        except:
-            print("Failed to parse line %s from %s" % (line, version_file))
-            raise
+    with open(version_file, 'r') as f:
+        version_dict = {}
+        for line in f:
+            line = line.strip()
+            if line == '':
+                continue
+            if line.startswith("#"):
+                continue
+            try:
+                split_line = line.split("=")
+                if split_line[1] != "":
+                    value = split_line[1].strip('"')
+                    version_dict[split_line[0]] = value
+            except:
+                print("Failed to parse line %s from %s" % (line, version_file))
+                raise
 
     return SambaVersion(version_dict, path, env=env, is_install=is_install)