From nobody Tue Feb 10 09:24:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593056083; cv=none; d=zohomail.com; s=zohoarc; b=jw6Ty1SrDjzeCsV9ErtLZLcT/kbYsl6G+0+RQAXQgfZ3LiUC48pYc6FLbIm9jOs5kZoD23j8XEskKyJUKHXKyIoZR5r8UB5C4XZLdDT3GNF4xim70MeEMmbIxgiepV9EJ/ypXyjbqp0nrN892dkbWDG8QmjJWxxPQV+xBUx8bqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593056083; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9OLHIpqC0GhsCjNNl7a67q1S7m+PQT0qdQDP8rAYtTA=; b=ge9Iltw6NNBc/Mr8wx0RYxcIgv3vF3F8GT9vD8pkVLsg0a5BBu++ImxMYLaDD6V6cY92s/90Cv8DxvlkN42JBSJpcn4odcNUpO5AfyjEa+YaW/xE7SvmJRVGZMR/iXrbq3AzNxccRhSPNJKTBclpTzkKx4YQ3wIaY0k8qJOcdHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1593056082994181.9400401344758; Wed, 24 Jun 2020 20:34:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-o_2qmHHsPa25Q07SLF9OfQ-1; Wed, 24 Jun 2020 23:34:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17815107ACF2; Thu, 25 Jun 2020 03:34:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE6265C557; Thu, 25 Jun 2020 03:34:29 +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 BF59B1809557; Thu, 25 Jun 2020 03:34:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05P3YMuC007775 for ; Wed, 24 Jun 2020 23:34:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 927015BAC0; Thu, 25 Jun 2020 03:34:22 +0000 (UTC) Received: from vhost2.laine.org (ovpn-114-28.phx2.redhat.com [10.3.114.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F11A5BAE5 for ; Thu, 25 Jun 2020 03:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593056081; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9OLHIpqC0GhsCjNNl7a67q1S7m+PQT0qdQDP8rAYtTA=; b=gibYFPYiBr8aQ2Wywikb8DpjnH/mOXr7Gd2VVn76+m8+DiD7bUqdZ6svWnk+R61+mLLmLF 8vBXrBmQoICBtlqbx3CxdintzVMlOHYVCZr/Yw9MM2UGJomQzI+LhsfiRQpIErjKc07zmQ 0p5xOSi0vFzkYEfyjyLpW+EGRcLqgPo= X-MC-Unique: o_2qmHHsPa25Q07SLF9OfQ-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 02/25] use g_autoptr for all xmlBuffers Date: Wed, 24 Jun 2020 23:33:51 -0400 Message-Id: <20200625033414.1819594-3-laine@redhat.com> In-Reply-To: <20200625033414.1819594-1-laine@redhat.com> References: <20200625033414.1819594-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" AUTOPTR_CLEANUP_FUNC is set to xmlBufferFree() in util/virxml.h (This is actually new - added accidentally (but fortunately harmlessly!) in commit 257aba2dafe. I had added it along with the hunks in this patch, then decided to remove it and submit separately, but missed taking out the hunk in virxml.h) Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 4 +--- src/conf/network_conf.c | 4 +--- src/util/virxml.c | 12 +++--------- src/vmx/vmx.c | 10 +++------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d057f8c78..1916b51d38 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29579,7 +29579,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefP= tr def, def->description); =20 if (def->metadata) { - xmlBufferPtr xmlbuf; + g_autoptr(xmlBuffer) xmlbuf =3D NULL; int oldIndentTreeOutput =3D xmlIndentTreeOutput; =20 /* Indentation on output requires that we previously set @@ -29596,12 +29596,10 @@ virDomainDefFormatInternalSetRootName(virDomainDe= fPtr def, =20 if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; goto error; } virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); - xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; } =20 diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 5b578f894c..4ebad1483c 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2508,7 +2508,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, virBufferAsprintf(buf, "%s\n", uuidstr); =20 if (def->metadata) { - xmlBufferPtr xmlbuf; + g_autoptr(xmlBuffer) xmlbuf =3D NULL; int oldIndentTreeOutput =3D xmlIndentTreeOutput; =20 /* Indentation on output requires that we previously set @@ -2525,12 +2525,10 @@ virNetworkDefFormatBuf(virBufferPtr buf, =20 if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; return -1; } virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); - xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; } =20 diff --git a/src/util/virxml.c b/src/util/virxml.c index 02b59ea2f8..848d549a8b 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -953,8 +953,7 @@ char * virXMLNodeToString(xmlDocPtr doc, xmlNodePtr node) { - xmlBufferPtr xmlbuf =3D NULL; - char *ret =3D NULL; + g_autoptr(xmlBuffer) xmlbuf =3D NULL; =20 if (!(xmlbuf =3D xmlBufferCreate())) { virReportOOMError(); @@ -964,15 +963,10 @@ virXMLNodeToString(xmlDocPtr doc, if (xmlNodeDump(xmlbuf, doc, node, 0, 1) =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to convert the XML node tree")); - goto cleanup; + return NULL; } =20 - ret =3D g_strdup((const char *)xmlBufferContent(xmlbuf)); - - cleanup: - xmlBufferFree(xmlbuf); - - return ret; + return g_strdup((const char *)xmlBufferContent(xmlbuf)); } =20 =20 diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index fa9766995c..67bbe27fde 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -697,8 +697,8 @@ virVMXConvertToUTF8(const char *encoding, const char *s= tring) { char *result =3D NULL; xmlCharEncodingHandlerPtr handler; - xmlBufferPtr input; - xmlBufferPtr utf8; + g_autoptr(xmlBuffer) input =3D NULL; + g_autoptr(xmlBuffer) utf8 =3D NULL; =20 handler =3D xmlFindCharEncodingHandler(encoding); =20 @@ -720,14 +720,10 @@ virVMXConvertToUTF8(const char *encoding, const char = *string) goto cleanup; } =20 - result =3D (char *)utf8->content; - utf8->content =3D NULL; + result =3D (char *)g_steal_pointer(&utf8->content); =20 cleanup: xmlCharEncCloseFunc(handler); - xmlBufferFree(input); - xmlBufferFree(utf8); - return result; } =20 --=20 2.25.4