From 757fe8cab8b09bc1c2acb6663e193a66b1802fe9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:40:57 +0000 Subject: [PATCH] Fix unclosed file descriptor in _resolvers_unix Replaced the direct open().read() pattern in _resolvers_unix with a proper `with open(...)` context manager to ensure the file descriptor for /etc/resolv.conf is deterministically closed, eliminating a potential file descriptor leak. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src/netsleuth/netinfo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/netsleuth/netinfo.py b/src/netsleuth/netinfo.py index 31badd7..565f503 100644 --- a/src/netsleuth/netinfo.py +++ b/src/netsleuth/netinfo.py @@ -201,7 +201,8 @@ def _resolvers_windows() -> dict[str, list[str]]: def _resolvers_unix() -> dict[str, list[str]]: adapters: dict[str, list[str]] = {} try: - text = open("/etc/resolv.conf", encoding="utf-8", errors="replace").read() + with open("/etc/resolv.conf", encoding="utf-8", errors="replace") as f: + text = f.read() except OSError: text = "" servers = [line.split()[1] for line in text.splitlines() if line.startswith("nameserver") and len(line.split()) > 1]