Re: [libvirt] [PATCH v2 9/9] reworked cpu-baseline command for virsh

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

 



> diff --git a/tools/virsh.c b/tools/virsh.c
> index 7db48d9..95f5801 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -7025,6 +7026,121 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
...
> +static int
> +cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
> +{
...
> +    for (i = 0;i < obj->nodesetval->nodeNr;i++) {
> +        buf = xmlBufferCreate();
> +        if (buf == NULL)
> +            goto no_memory;
> +        sctxt = xmlSaveToBuffer(buf, NULL, 0);
> +        if (sctxt == NULL)
Hmm, we would leak buf here, wouldn't we?
> +            goto no_memory;
> +
> +        xmlSaveTree(sctxt, obj->nodesetval->nodeTab[i]);
> +        xmlSaveClose(sctxt);
> +
> +        list = vshRealloc(ctl, list, sizeof(char *) * (count + 1));
> +        list[count++] = (char *) buf->content;
> +        buf->content = NULL;
> +        buf = NULL;
> +    }
> +
> +    if (count == 0) {
> +        vshError(ctl, _("No host CPU specified in '%s'"), from);
> +        ret = FALSE;
> +        goto cleanup;
> +    }
> +
> +    result = virConnectBaselineCPU(ctl->conn, list, count, 0);
> +
> +    if (result)
> +        vshPrint(ctl, "%s", result);
> +    else
> +        ret = FALSE;
> +
> +cleanup:
> +    xmlXPathFreeObject(obj);
> +    xmlXPathFreeContext(ctxt);
> +    xmlFreeDoc(doc);
> +    VIR_FREE(result);
> +    if ((list != NULL) && (count > 0)) {
> +        for (i = 0;i < count;i++)
> +            VIR_FREE(list[i]);
> +    }
> +    VIR_FREE(list);
> +    VIR_FREE(buffer);

This would fix the leak:
       xmlBufferFree(buf);

> +    return ret;
> +
> +no_memory:
> +    vshError(ctl, "%s", _("Out of memory"));
> +    ret = FALSE;
> +}

Except for the leak on error path, the patch looks good. ACK for the fixed
version.

Jirka

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]