[Libvirt-cim] [PATCH] Fix possible memory leaks

Daniel Veillard veillard at redhat.com
Tue Mar 13 06:52:34 UTC 2012


On Tue, Mar 06, 2012 at 02:45:55PM -0300, Eduardo Lima (Etrunko) wrote:
> From: "Eduardo Lima (Etrunko)" <eblima at br.ibm.com>
> 
> Another Coverity scan report provided by Red Hat:
> https://bugzilla.redhat.com/show_bug.cgi?id=750418#c10
> 
> Error: RESOURCE_LEAK:
> Virt_AppliedFilterList.c:608: alloc_arg: Calling allocation function "get_dominfo" on "dominfo".
> device_parsing.c:1251: alloc_arg: "get_dominfo_from_xml" allocates memory that is stored into "*dominfo".
> device_parsing.c:1205: alloc_fn: Storage is returned from allocation function "calloc".
> device_parsing.c:1205: var_assign: Assigning: "*dominfo" = "calloc(1UL, 216UL)".
> device_parsing.c:1209: noescape: Variable "*dominfo" is not freed or pointed-to in function "_get_dominfo".
> device_parsing.c:1168:57: noescape: "_get_dominfo" does not free or save its pointer parameter "dominfo".
> Virt_AppliedFilterList.c:644: leaked_storage: Variable "dominfo" going out of scope leaks the storage it points to.
> 
> Error: RESOURCE_LEAK:
> Virt_AppliedFilterList.c:485: alloc_arg: Calling allocation function "get_dominfo" on "dominfo".
> device_parsing.c:1251: alloc_arg: "get_dominfo_from_xml" allocates memory that is stored into "*dominfo".
> device_parsing.c:1205: alloc_fn: Storage is returned from allocation function "calloc".
> device_parsing.c:1205: var_assign: Assigning: "*dominfo" = "calloc(1UL, 216UL)".
> device_parsing.c:1209: noescape: Variable "*dominfo" is not freed or pointed-to in function "_get_dominfo".
> device_parsing.c:1168:57: noescape: "_get_dominfo" does not free or save its pointer parameter "dominfo".
> Virt_AppliedFilterList.c:529: leaked_storage: Variable "dominfo" going out of scope leaks the storage it points to.
> 
> Error: RESOURCE_LEAK:
> misc_util.c:275: alloc_arg: Calling allocation function "get_domain_list" on "list".
> cs_util_instance.c:52: alloc_fn: Storage is returned from allocation function "calloc".
> cs_util_instance.c:52: var_assign: Assigning: "list" = "calloc(n_names + n_ids, 8UL)".
> cs_util_instance.c:112: var_assign: Assigning: "*_list" = "list".
> misc_util.c:277: leaked_storage: Variable "list" going out of scope leaks the storage it points to.
> 
> Signed-off-by: Eduardo Lima (Etrunko) <eblima at br.ibm.com>
> ---
>  libxkutil/misc_util.c        |    6 +++---
>  src/Virt_AppliedFilterList.c |    4 ++--
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
> index 61893c3..2d149ae 100644
> --- a/libxkutil/misc_util.c
> +++ b/libxkutil/misc_util.c
> @@ -267,14 +267,14 @@ bool match_pn_to_cn(const char *pn, const char *cn)
>  
>  uint64_t allocated_memory(virConnectPtr conn)
>  {
> -        virDomainPtr *list;
> +        virDomainPtr *list = NULL;
>          int count;
>          int i;
>          uint64_t memory = 0;
>  
>          count = get_domain_list(conn, &list);
>          if (count <= 0)
> -                return 0;
> +                goto end;
>  
>          for (i = 0; i < count; i ++) {
>                  virDomainPtr dom = list[i];
> @@ -286,8 +286,8 @@ uint64_t allocated_memory(virConnectPtr conn)
>                  virDomainFree(dom);
>          }
>  
> + end:
>          free(list);
> -
>          return memory;
>  }
>  
> diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c
> index 538adf4..0dfe6a3 100644
> --- a/src/Virt_AppliedFilterList.c
> +++ b/src/Virt_AppliedFilterList.c
> @@ -521,7 +521,7 @@ static CMPIStatus CreateInstance(
>          free(net_name);
>  
>          cleanup_filters(&filter, 1);
> -        cleanup_virt_devices(&device, 1);
> +        cleanup_dominfo(&dominfo);
>  
>          virDomainFree(dom);
>          virConnectClose(conn);
> @@ -636,7 +636,7 @@ static CMPIStatus DeleteInstance(
>          free(net_name);
>  
>          cleanup_filters(&filter, 1);
> -        cleanup_virt_devices(&device, 1);
> +        cleanup_dominfo(&dominfo);
>  
>          virDomainFree(dom);
>          virConnectClose(conn);

  Our QE confirmed that this fixed the leak detected,

   ACK from me :)

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the Libvirt-cim mailing list