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

Aline Manera alinefm at linux.vnet.ibm.com
Thu Jan 22 17:41:42 UTC 2015


Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 20/01/2015 06:45, lvroyce at linux.vnet.ibm.com wrote:
> 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




More information about the Kimchi-devel mailing list