[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] [PATCH] Fix some memory leaks in xs_internal.c



On Fri, Aug 17, 2007 at 04:21:19PM +0900, Masayuki Sunou wrote:
> Hi
> 
> Some memory releases is missed in xs_internal.c.
> This patch fixes it.

  Hum, good catch !

> Signed-off-by: Masayuki Sunou <fj1826dm aa jp fujitsu com>
> 
> Thanks,
> Masayuki Sunou.
> 
> ----------------------------------------------------------------------
> Index: src/xs_internal.c
> ===================================================================
> RCS file: /data/cvs/libvirt/src/xs_internal.c,v
> retrieving revision 1.47
> diff -u -p -r1.47 xs_internal.c
> --- src/xs_internal.c	10 Aug 2007 18:25:15 -0000	1.47
> +++ src/xs_internal.c	17 Aug 2007 05:19:00 -0000
> @@ -578,6 +578,8 @@ xenStoreListDomains(virConnectPtr conn, 
>  #endif
>  	ids[ret++] = (int) id;
>      }
> +    if (idlist)
> +        free(idlist);

  Actually we know idlist != NULL at that point, so the test is not needed.

>      return(ret);
>  }
>  
> @@ -637,11 +639,10 @@ xenStoreLookupByName(virConnectPtr conn,
>      path = xs_get_domain_path(priv->xshandle, (unsigned int) id);
>  
>      if (!found)
> -        return(NULL);
> +        goto done;

  I wonder if there isn't a bug there actually, if (!found) we should
not get the domain path, it's at least non-optimal. I moved the test 
just after the loop where found is set and before xs_get_domain_path()
Actually upon further looking, path is never used. It used to be stored in
the domain IIRC, but here we look for the value and never use it, it just
got freed, so I'm cleaning up that part !

>      ret = virGetDomain(conn, name, NULL);
>      if (ret == NULL) {
> -        if (path != NULL) free(path);
>          goto done;
>      }
>      ret->id = id;
> @@ -651,6 +652,8 @@ done:
>  	free(xenddomain);
>      if (idlist != NULL)
>  	free(idlist);
> +    if (path != NULL)
> +        free(path);
>  
>      return(ret);
>  }
> ----------------------------------------------------------------------

  that code just disapeared ! thanks for raising this !
I will commit this as soon as I can get the DNS for xmlsoft.org a.k.a.
libvirt.org fixed,

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]