vms: don't leak vsock sockets in error case

This commit is contained in:
Jörg Thalheim
2024-12-11 16:49:03 +01:00
committed by Mic92
parent cf2033441c
commit cabdca4cd7

View File

@@ -16,9 +16,8 @@ def test_vsock_port(port: int) -> bool:
msg = "vsock is only supported on Linux"
raise NotImplementedError(msg)
try:
s = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
with socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM) as s:
s.connect((VMADDR_CID_HYPERVISOR, port))
s.close()
except OSError:
return False
else: