diff options
author | Christian Ulrich <christian@ulrich.earth> | 2020-10-12 22:02:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 22:02:17 +0200 |
commit | 1f51a3399808218f99e820fd43f5bd9d2204ce61 (patch) | |
tree | 41d4f3e11abcc1e0610c3d8c459cef8cf7396447 | |
parent | 30b966bdf7ea898f5cda9bcd3d9470d17eba5634 (diff) | |
download | Nim-1f51a3399808218f99e820fd43f5bd9d2204ce61.tar.gz |
close socket in getPrimaryIPAddr even if exception occurs (#15558)
-rw-r--r-- | lib/pure/net.nim | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 3f768470d..3ef41aa3c 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -2005,6 +2005,8 @@ proc getPrimaryIPAddr*(dest = parseIpAddress("8.8.8.8")): IpAddress = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) else: newSocket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP) - socket.connect($dest, 80.Port) - result = socket.getLocalAddr()[0].parseIpAddress() - socket.close() + try: + socket.connect($dest, 80.Port) + result = socket.getLocalAddr()[0].parseIpAddress() + finally: + socket.close() |