[Kimchi-devel] [kimchi-devel][PATCH 5/7] Fix leak in check_url_path

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Tue Jan 20 08:45:08 UTC 2015


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

url opened without close, fix it with contextlib

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/utils.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index 6acfa42..a279bc0 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -19,6 +19,7 @@
 #
 
 import cherrypy
+import contextlib
 import grp
 import os
 import psutil
@@ -147,7 +148,8 @@ def check_url_path(path):
         urlpath = parse_result.path
         if not urlpath:
             # Just a server, as with a repo.
-            code = urllib2.urlopen(path).getcode()
+            with contextlib.closing(urllib2.urlopen(path)) as res:
+                code = res.getcode()
         else:
             # socket.gaierror could be raised,
             #   which is a child class of IOError
-- 
1.9.3




More information about the Kimchi-devel mailing list