[Libvirt-cim] [PATCH 2 of 6] Add domain information store utilities

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Jun 18 17:45:47 UTC 2008


> +static char *make_filename(virDomainPtr dom)
> +{
> +        virConnectPtr conn;
> +        char *path = NULL;
> +
> +        conn = virDomainGetConnect(dom);
> +        if (conn == NULL) {
> +                CU_DEBUG("Domain has no libvirt connection");
> +                goto out;
> +        }
> +
> +        path = _make_filename(virConnectGetType(conn),
> +                              virDomainGetName(dom));
> +
> +        CU_DEBUG("Path is %s", path);
> +
> + out:

Need to close the connection here.

> +        return path;
> +}
> +
> +static xmlDocPtr parse_xml(int fd)
> +{
> +        xmlParserCtxtPtr ctx = NULL;
> +        xmlDocPtr doc = NULL;
> +
> +        ctx = xmlNewParserCtxt();
> +        if (ctx == NULL)
> +                goto err;
> +
> +        doc = xmlCtxtReadFd(ctx,
> +                            fd,
> +                            "foo",
> +                            NULL,
> +                            XML_PARSE_NOWARNING | XML_PARSE_NONET);
> +        if (doc == NULL)
> +                goto err;

Before returning, the xmlParserCtxtPtr should be freed.

> +
> +        return doc;
> + err:
> +        xmlFreeDoc(doc);
> +        xmlFreeParserCtxt(ctx);
> +
> +        return NULL;
> +}
> +


> +bool infostore_set_u64(struct infostore_ctx *ctx, const char *key, uint64_t val)
> +{
> +        char *sval = NULL;
> +
> +        if (asprintf(&sval, "%" PRIu64, val) == -1) {
> +                CU_DEBUG("Failed to format u64 string");
> +                sval = NULL;
> +                goto out;
> +        }
> +
> +        xpath_set_string(ctx, key, sval);
> + out:
> +        free(sval);
> +
> +        return false;

Not sure why you only return false here.  In every place you've called 
it, you're not capturing the return, so the value doesn't really matter. 
  However, just curious why it's false.

-- 
Kaitlin Rupert
IBM Linux Technology Center
kaitlin at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list