Skip to content

Commit 72f451e

Browse files
decsnynashif
authored andcommitted
scripts: kconfiglib: Fix file leaks
Fixing a couple cases of a programming error where a file is not closed in case of an exception, which was causing resource leak warnings in some cases when encountering a kconfig error. Signed-off-by: Declan Snyder <[email protected]>
1 parent efdd858 commit 72f451e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

scripts/kconfig/kconfiglib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,10 +1087,10 @@ def _init(self, filename, warn, warn_to_stderr, encoding):
10871087
self.top_node.next = None
10881088
except UnicodeDecodeError as e:
10891089
_decoding_error(e, self.filename)
1090-
1091-
# Close the top-level Kconfig file. __self__ fetches the 'file' object
1092-
# for the method.
1093-
self._readline.__self__.close()
1090+
finally:
1091+
# Close the top-level Kconfig file. __self__ fetches the 'file' object
1092+
# for the method.
1093+
self._readline.__self__.close()
10941094

10951095
self._parsing_kconfigs = False
10961096

@@ -2998,8 +2998,10 @@ def _parse_block(self, end_token, parent, prev):
29982998

29992999
for filename in filenames:
30003000
self._enter_file(filename)
3001-
prev = self._parse_block(None, parent, prev)
3002-
self._leave_file()
3001+
try:
3002+
prev = self._parse_block(None, parent, prev)
3003+
finally:
3004+
self._leave_file()
30033005

30043006
elif t0 is end_token:
30053007
# Reached the end of the block. Terminate the final node and

0 commit comments

Comments
 (0)