[PATCH v5 11/13] scripts: generate_rust_analyzer.py: avoid FD leak

Tamir Duberstein
2025-03-25T20:07:00Z

Use a context manager to avoid leaking file descriptors.

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
scripts/generate_rust_analyzer.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index ea4dd68d0dd9..e3f1ec856ecf 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -251,7 +251,8 @@ def generate_crates(

def is_root_crate(build_file: pathlib.Path, target: str) -> bool:
try:
- return f"{target}.o" in open(build_file).read()
+ with open(build_file) as f:
+ return f"{target}.o" in f.read()
except FileNotFoundError:
return False

--
2.49.0