]> granicus.if.org Git - python/commitdiff
#15277: Fix a resource leak in support.py when IPv6 is disabled.
authorRoss Lagerwall <rosslagerwall@gmail.com>
Sat, 7 Jul 2012 16:40:32 +0000 (18:40 +0200)
committerRoss Lagerwall <rosslagerwall@gmail.com>
Sat, 7 Jul 2012 16:40:32 +0000 (18:40 +0200)
The leak occurred by setting:
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
before running test_support.

Patch by Brian Brazil.

Lib/test/support.py
Misc/NEWS

index ddd3ab619a6c913f704e5467d8be708cf486bc2f..2d7f70df07fbbde3c8e7da2e3f3dfe512c8b38cc 100644 (file)
@@ -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()
index a109baf039fe9e707cbba424f02c6a9f8bc5a50a..dada87b7cf64f75ea98850fa20712488e4092544 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -74,6 +74,12 @@ Tools/Demos
     * C frames that are garbage-collecting
     * C frames that are due to the invocation of a PyCFunction
 
+Tests
+-----
+
+- Issue #15277: Fix a resource leak in support.py when IPv6 is disabled.
+  Patch by Brian Brazil.
+
 Build
 -----