mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 19:12:03 +03:00
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:
parent
8c99ac78b7
commit
757fe8cab8
1 changed files with 2 additions and 1 deletions
|
|
@ -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]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue