[Libvirt-cim] [PATCH 08/10] libxkutil: Adjust get_dominfo() logic

Wenchao Xia xiawenc at linux.vnet.ibm.com
Fri Mar 15 08:25:47 UTC 2013


于 2013-3-15 6:56, John Ferlan 写道:
> Need to really handle the error on the get_dominfo_from_xml() call
>
> Need to be sure to free(xml) before returning
> ---
>   libxkutil/device_parsing.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
> index 2841662..264d4cc 100644
> --- a/libxkutil/device_parsing.c
> +++ b/libxkutil/device_parsing.c
> @@ -1246,7 +1246,7 @@ int get_dominfo_from_xml(const char *xml, struct domain **dominfo)
>   int get_dominfo(virDomainPtr dom, struct domain **dominfo)
>   {
>           char *xml;
> -        int ret;
> +        int ret = 0;
>           int start;
>           xml = virDomainGetXMLDesc(dom,
>                   VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
> @@ -1256,17 +1256,19 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo)
>                   return 0;
>           }
>
> -        ret = get_dominfo_from_xml(xml, dominfo);
> -        if (ret != 1) {
> +        if (get_dominfo_from_xml(xml, dominfo) == 0) {
>                   CU_DEBUG("Failed to translate xml into struct domain");
> +                goto out;
>           }
>           if (virDomainGetAutostart(dom,  &start) !=  0) {
>                   CU_DEBUG("Failed to get dom autostart with libvirt API.");
> -                return 0;
> +                goto out;
>           }
>
>           (*dominfo)->autostrt = start;
> +        ret = 1;
>
> + out:
>           free(xml);
>
>           return ret;
>
   Fixed a leak, +1

-- 
Best Regards

Wenchao Xia




More information about the Libvirt-cim mailing list