Use VIR_AUTOCLEAN to avoid leaking the buffer on error path and get rid of resetting mid loop since virXMLFormatElement does the reset internally. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_conf.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 52022aed0b..605ae3667b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27745,8 +27745,8 @@ static int virDomainDefFormatFeatures(virBufferPtr buf, virDomainDefPtr def) { - virBuffer tmpAttrBuf = VIR_BUFFER_INITIALIZER; - virBuffer tmpChildBuf = VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) tmpAttrBuf = VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) tmpChildBuf = VIR_BUFFER_INITIALIZER; size_t i; for (i = 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { @@ -27784,8 +27784,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, case VIR_TRISTATE_SWITCH_OFF: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected state of feature '%s'"), name); - - goto error; + return -1; break; } @@ -27835,7 +27834,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, } if (virXMLFormatElement(buf, "smm", &attrBuf, &childBuf) < 0) - goto error; + return -1; } break; @@ -27973,9 +27972,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, if (def->features[i] != VIR_TRISTATE_SWITCH_ON) break; - virBufferFreeAndReset(&tmpAttrBuf); - virBufferFreeAndReset(&tmpChildBuf); - if (def->hpt_resizing != VIR_DOMAIN_HPT_RESIZING_NONE) { virBufferAsprintf(&tmpAttrBuf, " resizing='%s'", @@ -27988,10 +27984,8 @@ virDomainDefFormatFeatures(virBufferPtr buf, def->hpt_maxpagesize); } - if (virXMLFormatElement(buf, "hpt", - &tmpAttrBuf, &tmpChildBuf) < 0) { - goto error; - } + if (virXMLFormatElement(buf, "hpt", &tmpAttrBuf, &tmpChildBuf) < 0) + return -1; break; case VIR_DOMAIN_FEATURE_MSRS: @@ -28012,11 +28006,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, virBufferAddLit(buf, "</features>\n"); return 0; - - error: - virBufferFreeAndReset(&tmpAttrBuf); - virBufferFreeAndReset(&tmpChildBuf); - return -1; } -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list