diff options
| author | Declan Snyder <declan.snyder@nxp.com> | 2025-10-23 23:21:35 +0200 |
|---|---|---|
| committer | Torsten Tejlmand Rasmussen <torsten.rasmussen@nordicsemi.no> | 2025-10-28 09:03:31 +0100 |
| commit | 9b1ae7845300bf248cf5ba71837791eb2141f195 (patch) | |
| tree | da29886b6ec04753f0d96910e53d15b7bdb7dbc7 | |
| parent | 1e6f6441222b756ec0fce46fe60752473e57bc4a (diff) | |
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 CabeĢ <benjamin@zephyrproject.org>
| -rw-r--r-- | kconfiglib.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 4506296..ce40eb7 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1087,10 +1087,10 @@ class Kconfig(object): self.top_node.next = None except UnicodeDecodeError as e: _decoding_error(e, self.filename) - - # Close the top-level Kconfig file. __self__ fetches the 'file' object - # for the method. - self._readline.__self__.close() + finally: + # Close the top-level Kconfig file. __self__ fetches the 'file' object + # for the method. + self._readline.__self__.close() self._parsing_kconfigs = False @@ -2984,8 +2984,10 @@ class Kconfig(object): for filename in filenames: self._enter_file(filename) - prev = self._parse_block(None, parent, prev) - self._leave_file() + try: + prev = self._parse_block(None, parent, prev) + finally: + self._leave_file() elif t0 is end_token: # Reached the end of the block. Terminate the final node and |
