From nobody Mon Feb 9 00:30:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551860478839306.65650524721593; Wed, 6 Mar 2019 00:21:18 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED97D318A613; Wed, 6 Mar 2019 08:21:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C143A6B478; Wed, 6 Mar 2019 08:21:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8115E3FA48; Wed, 6 Mar 2019 08:21:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x268L491032572 for ; Wed, 6 Mar 2019 03:21:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id B2C5828542; Wed, 6 Mar 2019 08:21:04 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36C37277B3 for ; Wed, 6 Mar 2019 08:21:04 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 6 Mar 2019 09:20:40 +0100 Message-Id: <445236e97871660c188cdea382cb6486fe68c8b2.1551859940.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/23] conf: Simplify lifecycle of temp buffers in virDomainDefFormatFeatures X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 06 Mar 2019 08:21:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko --- 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 =3D VIR_BUFFER_INITIALIZER; - virBuffer tmpChildBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) tmpAttrBuf =3D VIR_BUFFER_INITIALIZER; + VIR_AUTOCLEAN(virBuffer) tmpChildBuf =3D VIR_BUFFER_INITIALIZER; size_t i; for (i =3D 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] !=3D VIR_TRISTATE_SWITCH_ON) break; - virBufferFreeAndReset(&tmpAttrBuf); - virBufferFreeAndReset(&tmpChildBuf); - if (def->hpt_resizing !=3D VIR_DOMAIN_HPT_RESIZING_NONE) { virBufferAsprintf(&tmpAttrBuf, " resizing=3D'%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, "\n"); return 0; - - error: - virBufferFreeAndReset(&tmpAttrBuf); - virBufferFreeAndReset(&tmpChildBuf); - return -1; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list