Skip to content

Commit 142a44b

Browse files
committed
scripts: check_init_priorities: Fix file leak
The elf file needs to be closed after done being used, otherwise sys module will generate resource leak warnings. Signed-off-by: Declan Snyder <[email protected]>
1 parent cf5da6b commit 142a44b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

scripts/build/check_init_priorities.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ class variables in the {"level name": ["call", ...]} format.
9898
Attributes:
9999
file_path: path of the file to be loaded.
100100
"""
101-
def __init__(self, file_path):
101+
def __init__(self, file_path, elf_file):
102102
self.file_path = file_path
103-
self._elf = ELFFile(open(file_path, "rb"))
103+
self._elf = ELFFile(elf_file)
104104
self._load_objects()
105105
self._load_level_addr()
106106
self._process_initlevels()
@@ -226,7 +226,7 @@ class Validator():
226226
edt_pickle: name of the EDT pickle file
227227
log: a logging.Logger object
228228
"""
229-
def __init__(self, elf_file_path, edt_pickle, log):
229+
def __init__(self, elf_file_path, edt_pickle, log, elf_file):
230230
self.log = log
231231

232232
edt_pickle_path = pathlib.Path(
@@ -237,7 +237,7 @@ def __init__(self, elf_file_path, edt_pickle, log):
237237

238238
self._ord2node = edt.dep_ord2node
239239

240-
self._obj = ZephyrInitLevels(elf_file_path)
240+
self._obj = ZephyrInitLevels(elf_file_path, elf_file)
241241

242242
self.errors = 0
243243

@@ -344,17 +344,18 @@ def main(argv=None):
344344

345345
log.info(f"check_init_priorities: {args.elf_file}")
346346

347-
validator = Validator(args.elf_file, args.edt_pickle, log)
348-
if args.initlevels:
349-
validator.print_initlevels()
350-
else:
351-
validator.check_edt()
347+
with open(args.elf_file, "rb") as elf_file:
348+
validator = Validator(args.elf_file, args.edt_pickle, log, elf_file)
349+
if args.initlevels:
350+
validator.print_initlevels()
351+
else:
352+
validator.check_edt()
352353

353-
if args.always_succeed:
354-
return 0
354+
if args.always_succeed:
355+
return 0
355356

356-
if validator.errors:
357-
return 1
357+
if validator.errors:
358+
return 1
358359

359360
return 0
360361

0 commit comments

Comments
 (0)