From nobody Mon Feb 9 03:48:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1614788284; cv=none; d=zohomail.com; s=zohoarc; b=kjw5NpMiJz2EaPhDOzLtOeXN735T7H6XSVQBfTYmwbMjBTGeGOurEMYMNdMSvG4t5Za6+uLKCO5B9+ejyvqBXTr1uZVPH17QKnWQB8Ogpc/N9YuokteorNr/5rJx/EOazEKaMXPpy8vjpkgfEeIz6eVUnoj6OMFNjvo7uk3PqXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614788284; 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=58mygBK3JmXi4OIjYUbYNb2HfWlASuDwYnV3DAa8E6Y=; b=SKLGfk4mngAlFoh0bpkHcJvek/XJMOCSxWczLO40Cm4jdgXNG91gBe9Z6Tt/C0D5uR7KtMMO4gx+JOGZ0XJTC8fUohBs+1B48g4jv4eUA+EumY/2fAI5qCdohPurvTIfuwBxc74M5zNz7oML4VHFgV8+co+C9Rd9LDLex0HosLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614788284583778.4315022274651; Wed, 3 Mar 2021 08:18:04 -0800 (PST) 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-358-AvmZAYrYMbqncYPx0xsQRg-1; Wed, 03 Mar 2021 11:17:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E83A195D562; Wed, 3 Mar 2021 16:17:52 +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 078FA5D705; Wed, 3 Mar 2021 16:17:52 +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 C1D7D4A7C6; Wed, 3 Mar 2021 16:17:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 123GHomB020417 for ; Wed, 3 Mar 2021 11:17:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 733E76091B; Wed, 3 Mar 2021 16:17:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE061707B6 for ; Wed, 3 Mar 2021 16:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614788283; 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=58mygBK3JmXi4OIjYUbYNb2HfWlASuDwYnV3DAa8E6Y=; b=GfasAr7TqPCmDm0e3fwd8Fe8zAHB1VaJXf6fB5EA8ME9GFV7xYrBClb/vritObP6n0GgO9 daXRYFKszm/XQ2MYC2moqU5asxC7xOuD82/Ny8PqQhjUK1/woLsbpxyBVlbg50qXL09E0o rzp3/SHPO7ZVBC8cwDLB+2IUfwTA5Hg= X-MC-Unique: AvmZAYrYMbqncYPx0xsQRg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 1/4] node_device_conf: Use g_autofree where possible Date: Wed, 3 Mar 2021 17:17:24 +0100 Message-Id: <27e2e67c37f88ba40408dd7f293293ddf1a6a33a.1614788020.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.15 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" Signed-off-by: Kristina Hanicova --- src/conf/node_device_conf.c | 76 +++++++++++-------------------------- 1 file changed, 23 insertions(+), 53 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 1093a461af..20fafd2c15 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -779,7 +779,7 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, { VIR_XPATH_NODE_AUTORESTORE(ctxt) int ret =3D -1, val; - char *type =3D NULL; + g_autofree char *type =3D NULL; =20 ctxt->node =3D node; =20 @@ -795,7 +795,6 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, ret =3D 0; =20 out: - VIR_FREE(type); return ret; } =20 @@ -807,7 +806,7 @@ virNodeDevCapMdevTypesParseXML(xmlXPathContextPtr ctxt, { int ret =3D -1; xmlNodePtr orignode =3D NULL; - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; int ntypes =3D -1; virMediatedDeviceTypePtr type =3D NULL; size_t i; @@ -859,7 +858,6 @@ virNodeDevCapMdevTypesParseXML(xmlXPathContextPtr ctxt, =20 ret =3D 0; cleanup: - VIR_FREE(nodes); virMediatedDeviceTypeFree(type); ctxt->node =3D orignode; return ret; @@ -1097,7 +1095,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virNodeDevCapStoragePtr storage) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; size_t i; int n, ret =3D -1; unsigned long long val; @@ -1122,7 +1120,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, goto out; =20 for (i =3D 0; i < n; i++) { - char *type =3D virXMLPropString(nodes[i], "type"); + g_autofree char *type =3D virXMLPropString(nodes[i], "type"); =20 if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1150,7 +1148,6 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, if (virNodeDevCapsDefParseULongLong("number(./media_size[1])",= ctxt, &val, def, _("no removable media size= supplied for '%s'"), _("invalid removable media= size supplied for '%s'")) < 0) { - VIR_FREE(type); goto out; } storage->removable_media_size =3D val; @@ -1160,11 +1157,8 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown storage capability type '%s' for '%s= '"), type, def->name); - VIR_FREE(type); goto out; } - - VIR_FREE(type); } =20 if (!(storage->flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { @@ -1178,7 +1172,6 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, =20 ret =3D 0; out: - VIR_FREE(nodes); return ret; } =20 @@ -1233,7 +1226,7 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ct= xt, virNodeDevCapSCSITargetPtr scsi_target) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; int ret =3D -1, n =3D 0; size_t i; char *type =3D NULL; @@ -1295,7 +1288,6 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ct= xt, =20 out: VIR_FREE(type); - VIR_FREE(nodes); return ret; } =20 @@ -1309,7 +1301,7 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, const char *virt_type) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; int ret =3D -1, n =3D 0; size_t i; char *type =3D NULL; @@ -1397,7 +1389,6 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, =20 out: VIR_FREE(type); - VIR_FREE(nodes); return ret; } =20 @@ -1413,7 +1404,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, size_t i =3D -1; int ret =3D -1, n =3D -1; char *tmp =3D NULL; - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; =20 ctxt->node =3D node; =20 @@ -1472,7 +1463,6 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, =20 ret =3D 0; out: - VIR_FREE(nodes); VIR_FREE(tmp); return ret; } @@ -1595,8 +1585,8 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContext= Ptr ctxt, virNodeDevCapPCIDevPtr pci_dev) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr *addrNodes =3D NULL; - char *numberStr =3D NULL; + g_autofree xmlNodePtr *addrNodes =3D NULL; + g_autofree char *numberStr =3D NULL; int nAddrNodes, ret =3D -1; size_t i; virPCIDeviceAddressPtr pciAddr =3D NULL; @@ -1637,8 +1627,6 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContext= Ptr ctxt, =20 ret =3D 0; cleanup: - VIR_FREE(numberStr); - VIR_FREE(addrNodes); VIR_FREE(pciAddr); return ret; } @@ -1651,7 +1639,8 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, { VIR_XPATH_NODE_AUTORESTORE(ctxt) int ret =3D -1, speed; - char *speedStr =3D NULL, *portStr =3D NULL; + g_autofree char *speedStr =3D NULL; + g_autofree char *portStr =3D NULL; =20 ctxt->node =3D linkNode; =20 @@ -1684,8 +1673,6 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, =20 ret =3D 0; cleanup: - VIR_FREE(portStr); - VIR_FREE(speedStr); return ret; } =20 @@ -1752,9 +1739,9 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextP= tr ctxt, virNodeDevCapPCIDevPtr pci_dev) { int ret =3D -1; - xmlNodePtr *addresses =3D NULL; + g_autofree xmlNodePtr *addresses =3D NULL; int naddresses =3D virXPathNodeSet("./address", ctxt, &addresses); - char *maxFuncsStr =3D virXPathString("string(./@maxCount)", ctxt); + g_autofree char *maxFuncsStr =3D virXPathString("string(./@maxCount)",= ctxt); size_t i; =20 if (naddresses < 0) @@ -1787,8 +1774,6 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextP= tr ctxt, pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; ret =3D 0; cleanup: - VIR_FREE(addresses); - VIR_FREE(maxFuncsStr); return ret; } =20 @@ -1798,7 +1783,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, xmlNodePtr node, virNodeDevCapPCIDevPtr pci_dev) { - char *type =3D virXMLPropString(node, "type"); + g_autofree char *type =3D virXMLPropString(node, "type"); VIR_XPATH_NODE_AUTORESTORE(ctxt) int ret =3D -1; =20 @@ -1830,7 +1815,6 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, =20 ret =3D 0; cleanup: - VIR_FREE(type); return ret; } =20 @@ -1844,11 +1828,11 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr iommuGroupNode; xmlNodePtr pciExpress; - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; int n =3D 0; int ret =3D -1; virPCIEDeviceInfoPtr pci_express =3D NULL; - char *tmp =3D NULL; + g_autofree char *tmp =3D NULL; size_t i =3D 0; =20 ctxt->node =3D node; @@ -1860,7 +1844,6 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, _("invalid PCI class supplied for '%s'"), def->= name); goto out; } - VIR_FREE(tmp); } else { pci_dev->klass =3D -1; } @@ -1911,7 +1894,6 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], pci_dev) < 0) goto out; } - VIR_FREE(nodes); =20 if ((iommuGroupNode =3D virXPathNode("./iommuGroup[1]", ctxt))) { if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, @@ -1940,8 +1922,6 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, =20 ret =3D 0; out: - VIR_FREE(nodes); - VIR_FREE(tmp); virPCIEDeviceInfoFree(pci_express); return ret; } @@ -1957,7 +1937,7 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, virNodeDevCapSystemFirmwarePtr firmware =3D &syscap->firmware; VIR_XPATH_NODE_AUTORESTORE(ctxt) int ret =3D -1; - char *tmp; + g_autofree char *tmp =3D NULL; =20 ctxt->node =3D node; =20 @@ -1977,10 +1957,8 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, if (virUUIDParse(tmp, hardware->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("malformed uuid element for '%s'"), def->name); - VIR_FREE(tmp); goto out; } - VIR_FREE(tmp); =20 firmware->vendor_name =3D virXPathString("string(./firmware/vendor[1]= )", ctxt); firmware->version =3D virXPathString("string(./firmware/version[1= ])", ctxt); @@ -2063,7 +2041,7 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, const char *virt_type) { virNodeDevCapsDefPtr caps; - char *tmp; + g_autofree char *tmp =3D NULL; int val, ret =3D -1; =20 caps =3D g_new0(virNodeDevCapsDef, 1); @@ -2078,11 +2056,9 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, if ((val =3D virNodeDevCapTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown capability type '%s'"), tmp); - VIR_FREE(tmp); goto error; } caps->data.type =3D val; - VIR_FREE(tmp); =20 switch (caps->data.type) { case VIR_NODE_DEV_CAP_SYSTEM: @@ -2198,7 +2174,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, =20 for (i =3D 0, m =3D 0; i < n; i++) { xmlNodePtr node =3D nodes[i]; - char *tmp =3D virXMLPropString(node, "type"); + g_autofree char *tmp =3D virXMLPropString(node, "type"); int val; =20 if (!tmp) { @@ -2212,10 +2188,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown devnode type '%s'"), tmp); - VIR_FREE(tmp); goto error; } - VIR_FREE(tmp); =20 switch ((virNodeDevDevnodeType)val) { case VIR_NODE_DEV_DEVNODE_DEV: @@ -2567,7 +2541,7 @@ virNodeDeviceCapsListExport(virNodeDeviceDefPtr def, virNodeDevCapType **list) { virNodeDevCapsDefPtr caps =3D NULL; - virNodeDevCapType *tmp =3D NULL; + g_autofree virNodeDevCapType *tmp =3D NULL; bool want_list =3D !!list; int ncaps =3D 0; int ret =3D -1; @@ -2639,7 +2613,6 @@ virNodeDeviceCapsListExport(virNodeDeviceDefPtr def, *list =3D g_steal_pointer(&tmp); ret =3D ncaps; cleanup: - VIR_FREE(tmp); return ret; } =20 @@ -2649,7 +2622,7 @@ virNodeDeviceCapsListExport(virNodeDeviceDefPtr def, int virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host) { - char *tmp =3D NULL; + g_autofree char *tmp =3D NULL; int ret =3D -1; =20 if ((scsi_host->unique_id =3D @@ -2698,7 +2671,6 @@ virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr= scsi_host) goto cleanup; } =20 - VIR_FREE(tmp); if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "npiv_vports_inuse"))) { VIR_WARN("Failed to read npiv_vports_inuse for host%d", @@ -2723,7 +2695,6 @@ virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr= scsi_host) VIR_FREE(scsi_host->wwpn); VIR_FREE(scsi_host->fabric_wwn); } - VIR_FREE(tmp); return ret; } =20 @@ -2733,7 +2704,8 @@ virNodeDeviceGetSCSITargetCaps(const char *sysfsPath, virNodeDevCapSCSITargetPtr scsi_target) { int ret =3D -1; - char *dir =3D NULL, *rport =3D NULL; + g_autofree char *dir =3D NULL; + g_autofree char *rport =3D NULL; =20 VIR_DEBUG("Checking if '%s' is an FC remote port", scsi_target->name); =20 @@ -2763,8 +2735,6 @@ virNodeDeviceGetSCSITargetCaps(const char *sysfsPath, VIR_FREE(scsi_target->wwpn); scsi_target->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_FC_RPORT; } - VIR_FREE(rport); - VIR_FREE(dir); =20 return ret; } --=20 2.29.2