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>
This commit is contained in:
google-labs-jules[bot] 2026-09-10 08:40:57 +00:00
parent 8c99ac78b7
commit 757fe8cab8

View file

@ -201,7 +201,8 @@ def _resolvers_windows() -> dict[str, list[str]]:
def _resolvers_unix() -> dict[str, list[str]]: def _resolvers_unix() -> dict[str, list[str]]:
adapters: dict[str, list[str]] = {} adapters: dict[str, list[str]] = {}
try: 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: except OSError:
text = "" text = ""
servers = [line.split()[1] for line in text.splitlines() if line.startswith("nameserver") and len(line.split()) > 1] servers = [line.split()[1] for line in text.splitlines() if line.startswith("nameserver") and len(line.split()) > 1]