Use virXMLFormatElement to format the internals along with simplifying cleanup code paths. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_conf.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ed480bcf8e..766846a557 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25921,36 +25921,18 @@ virDomainWatchdogDefFormat(virBufferPtr buf, static int virDomainPanicDefFormat(virBufferPtr buf, virDomainPanicDefPtr def) { - virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; - int ret = -1; - - virBufferAddLit(buf, "<panic"); + VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; if (def->model) - virBufferAsprintf(buf, " model='%s'", + virBufferAsprintf(&attrBuf, " model='%s'", virDomainPanicModelTypeToString(def->model)); virBufferSetChildIndent(&childrenBuf, buf); if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) - goto cleanup; - - if (virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "</panic>\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } - - ret = 0; - - cleanup: - virBufferFreeAndReset(&childrenBuf); + return -1; - return ret; + return virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf); } static int -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list