Skip to content

Commit 1701543

Browse files
Declan Snyderjserv
authored andcommitted
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 <declan.snyder@nxp.com> Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent da6ffc3 commit 1701543

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

kconfiglib.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,10 @@ def _init(
11451145
self.top_node.next = None
11461146
except UnicodeDecodeError as e:
11471147
_decoding_error(e, self.filename)
1148-
1149-
# Close the top-level Kconfig file. __self__ fetches the 'file' object
1150-
# for the method.
1151-
self._readline.__self__.close()
1148+
finally:
1149+
# Close the top-level Kconfig file. __self__ fetches the 'file' object
1150+
# for the method.
1151+
self._readline.__self__.close()
11521152

11531153
self._parsing_kconfigs = False
11541154

@@ -3112,8 +3112,10 @@ def _parse_block(self, end_token, parent, prev):
31123112

31133113
for filename in filenames:
31143114
self._enter_file(filename)
3115-
prev = self._parse_block(None, parent, prev)
3116-
self._leave_file()
3115+
try:
3116+
prev = self._parse_block(None, parent, prev)
3117+
finally:
3118+
self._leave_file()
31173119

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

0 commit comments

Comments
 (0)