diff options
author | Joseph Sutton <josephsutton@catalyst.net.nz> | 2023-02-21 11:38:54 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2023-03-03 01:07:36 +0000 |
commit | fa4ddb887ab3f88c65c21f6a55376e65a7447f27 (patch) | |
tree | e49139feb055e7910e1881e77cb444573f9355f4 /buildtools | |
parent | d8d872e09503fb6f636d7876573debcfa75c485e (diff) | |
download | samba-fa4ddb887ab3f88c65c21f6a55376e65a7447f27.tar.gz |
samba_version.py: Avoid resource leak
View with 'git show -b'.
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'buildtools')
-rw-r--r-- | buildtools/wafsamba/samba_version.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py index 5df7ddbcb3d..54ae62f38bd 100644 --- a/buildtools/wafsamba/samba_version.py +++ b/buildtools/wafsamba/samba_version.py @@ -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) |