提交 b0ae5083 编写于 作者: P Peter Krempa

util: xml: Always consume args of virXMLFormatElement

The function clears and frees the passed buffers on success, but not in
one case of failure. Modify the control flow that the args are always
consumed, record it in the docs and remove few pointless cleanup paths
in callers.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 0ba4da58
......@@ -24042,7 +24042,6 @@ virDomainDiskDefFormatIotune(virBufferPtr buf,
virDomainDiskDefPtr disk)
{
virBuffer childBuf = VIR_BUFFER_INITIALIZER;
int ret = -1;
virBufferSetChildIndent(&childBuf, buf);
......@@ -24077,10 +24076,7 @@ virDomainDiskDefFormatIotune(virBufferPtr buf,
FORMAT_IOTUNE(read_iops_sec_max_length);
FORMAT_IOTUNE(write_iops_sec_max_length);
ret = virXMLFormatElement(buf, "iotune", NULL, &childBuf);
virBufferFreeAndReset(&childBuf);
return ret;
return virXMLFormatElement(buf, "iotune", NULL, &childBuf);
}
#undef FORMAT_IOTUNE
......@@ -24091,7 +24087,6 @@ virDomainDiskDefFormatDriver(virBufferPtr buf,
virDomainDiskDefPtr disk)
{
virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
int ret = -1;
virBufferEscapeString(&driverBuf, " name='%s'", virDomainDiskGetDriver(disk));
......@@ -24143,10 +24138,7 @@ virDomainDiskDefFormatDriver(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverBuf, disk->virtio);
ret = virXMLFormatElement(buf, "driver", &driverBuf, NULL);
virBufferFreeAndReset(&driverBuf);
return ret;
return virXMLFormatElement(buf, "driver", &driverBuf, NULL);
}
......
......@@ -2234,14 +2234,11 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
{
virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
bool bj = qemuDomainHasBlockjob(vm, false);
int ret;
virBufferAsprintf(&attrBuf, " active='%s'",
virTristateBoolTypeToString(virTristateBoolFromBool(bj)));
ret = virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL);
virBufferFreeAndReset(&attrBuf);
return ret;
return virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL);
}
......
......@@ -1359,6 +1359,8 @@ virXMLValidatorFree(virXMLValidatorPtr validator)
* @childBuf are NULL or are empty buffers the element is not
* formatted.
*
* Both passed buffers are always consumed and freed.
*
* Returns 0 on success, -1 on error.
*/
int
......@@ -1367,15 +1369,16 @@ virXMLFormatElement(virBufferPtr buf,
virBufferPtr attrBuf,
virBufferPtr childBuf)
{
int ret = -1;
if ((!attrBuf || virBufferUse(attrBuf) == 0) &&
(!childBuf || virBufferUse(childBuf) == 0)) {
return 0;
}
if ((attrBuf && virBufferCheckError(attrBuf) < 0) ||
(childBuf && virBufferCheckError(childBuf) < 0)) {
return -1;
}
(childBuf && virBufferCheckError(childBuf) < 0))
goto cleanup;
virBufferAsprintf(buf, "<%s", name);
......@@ -1390,5 +1393,10 @@ virXMLFormatElement(virBufferPtr buf,
virBufferAddLit(buf, "/>\n");
}
return 0;
ret = 0;
cleanup:
virBufferFreeAndReset(attrBuf);
virBufferFreeAndReset(childBuf);
return ret;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册