summaryrefslogtreecommitdiff
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2012-07-07 18:40:32 +0200
committerRoss Lagerwall <rosslagerwall@gmail.com>2012-07-07 18:40:32 +0200
commit121d59ffa98d20b20e849b4c7333a723803f6798 (patch)
tree2a0cc915b2805f336f8b5d62762f92ae98389537 /Lib/test/support.py
parent9a9c28ce7a051b37a91e4fc7aef70bcdcda25047 (diff)
downloadcpython-git-121d59ffa98d20b20e849b4c7333a723803f6798.tar.gz
#15277: Fix a resource leak in support.py when IPv6 is disabled.
The leak occurred by setting: echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 before running test_support. Patch by Brian Brazil.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index ddd3ab619a..2d7f70df07 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -493,14 +493,16 @@ def bind_port(sock, host=HOST):
def _is_ipv6_enabled():
"""Check whether IPv6 is enabled on this host."""
if socket.has_ipv6:
+ sock = None
try:
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.bind(('::1', 0))
+ return True
except (socket.error, socket.gaierror):
pass
- else:
- sock.close()
- return True
+ finally:
+ if sock:
+ sock.close()
return False
IPV6_ENABLED = _is_ipv6_enabled()