From nobody Mon Feb 9 08:55:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1613167663; cv=none; d=zohomail.com; s=zohoarc; b=TTVeoM+JLqw5/cTHOMBHqCcRpkRuLru4QQXTuqjs81WhD/CnNHtYVuKYgY+kkWipPErS+dsYks9wv70WiFrMBDjaqkQUXAkdkqewjcPeX3RmOhM1uJdImTJITXHC8DX5hXW2+jCUMHqZFXQj9cNxbErT0TQfSyoDEECwlP9V9NY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613167663; 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=Jq96KHr4rVhRu1T9+W8xmQMKdjMoEntKJyJFku7UIyk=; b=Bkys3L3c185ngms2STTSdzy2Qzt5oCR5huaN/CwyX/pbc0370uZz7wTEAz/hj4hs+RzYt1bENKzuw+H005rMZO+lekopmb4fXXq5uVZYBmqIAf32ic+gdV38g8uTOprUaljLz9QZa31o5yaD1sa+Zo7rH0zSRuvIM+0yxWP6rHM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1613167662819237.69095117312088; Fri, 12 Feb 2021 14:07:42 -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-477-uar5-RTWNy-129l43AS4Cw-1; Fri, 12 Feb 2021 17:07:35 -0500 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 1F79A106BC69; Fri, 12 Feb 2021 22:07:29 +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 1D74B5C3FD; Fri, 12 Feb 2021 22:07:28 +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 A6C6918095CB; Fri, 12 Feb 2021 22:07:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11CM7MCm006132 for ; Fri, 12 Feb 2021 17:07:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 500F11002388; Fri, 12 Feb 2021 22:07:22 +0000 (UTC) Received: from vhost2.router.laine.org (ovpn-112-48.phx2.redhat.com [10.3.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1601A1001E73 for ; Fri, 12 Feb 2021 22:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613167657; 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=Jq96KHr4rVhRu1T9+W8xmQMKdjMoEntKJyJFku7UIyk=; b=hKdlZ5X4kcpW3JPkDYe/GFemsZpSrbupw9gLYKJjtSMV1q1iVGUl/T9EzX83uGDK5tR1XW TO3wz84wgOhgiIbch3kzYsicl0i6/Zwon/yCrgbO2ZOZ4hM97WotQywYp/vl2+2m+Qfn5M ulBNwttUNWCb+3WvXrMoYwlqRldvoqE= X-MC-Unique: uar5-RTWNy-129l43AS4Cw-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 2/9] esx: use g_autofree when made possible by reducing scope Date: Fri, 12 Feb 2021 17:07:10 -0500 Message-Id: <20210212220717.910294-3-laine@redhat.com> In-Reply-To: <20210212220717.910294-1-laine@redhat.com> References: <20210212220717.910294-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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" These strings were being VIR_FREEd multiple times because they were defined at the top of a function, but then set each time through a loop. But they are only used inside that loop, so they can be converted to use g_autofree if their definition is also placed inside that loop. Signed-off-by: Laine Stump --- src/esx/esx_driver.c | 13 ++++--------- src/esx/esx_storage_backend_iscsi.c | 12 ++++-------- src/esx/esx_storage_backend_vmfs.c | 18 ++++-------------- src/esx/esx_vi.c | 5 +---- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index df257341b8..8afec464dd 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -1391,7 +1391,6 @@ esxDomainLookupByID(virConnectPtr conn, int id) esxVI_ObjectContent *virtualMachine =3D NULL; esxVI_VirtualMachinePowerState powerState; int id_candidate =3D -1; - char *name_candidate =3D NULL; unsigned char uuid_candidate[VIR_UUID_BUFLEN]; virDomainPtr domain =3D NULL; =20 @@ -1410,6 +1409,8 @@ esxDomainLookupByID(virConnectPtr conn, int id) =20 for (virtualMachine =3D virtualMachineList; virtualMachine; virtualMachine =3D virtualMachine->_next) { + g_autofree char *name_candidate =3D NULL; + if (esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) { goto cleanup; @@ -1419,8 +1420,6 @@ esxDomainLookupByID(virConnectPtr conn, int id) if (powerState =3D=3D esxVI_VirtualMachinePowerState_PoweredOff) continue; =20 - VIR_FREE(name_candidate); - if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id_candidate, &name_candidate, uuid_candidate) < 0) { @@ -1444,8 +1443,6 @@ esxDomainLookupByID(virConnectPtr conn, int id) cleanup: esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&virtualMachineList); - VIR_FREE(name_candidate); - return domain; } =20 @@ -4754,7 +4751,6 @@ esxConnectListAllDomains(virConnectPtr conn, esxVI_AutoStartPowerInfo *powerInfoList =3D NULL; esxVI_AutoStartPowerInfo *powerInfo =3D NULL; esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList =3D NULL; - char *name =3D NULL; int id; unsigned char uuid[VIR_UUID_BUFLEN]; int count =3D 0; @@ -4839,9 +4835,9 @@ esxConnectListAllDomains(virConnectPtr conn, =20 for (virtualMachine =3D virtualMachineList; virtualMachine; virtualMachine =3D virtualMachine->_next) { - if (needIdentity) { - VIR_FREE(name); + g_autofree char *name =3D NULL; =20 + if (needIdentity) { if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, uuid) < 0) { goto cleanup; @@ -4959,7 +4955,6 @@ esxConnectListAllDomains(virConnectPtr conn, VIR_FREE(doms); } =20 - VIR_FREE(name); esxVI_AutoStartDefaults_Free(&autoStartDefaults); esxVI_AutoStartPowerInfo_Free(&powerInfoList); esxVI_String_Free(&propertyNameList); diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index 4d16ba2520..41bb9f6094 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -494,7 +494,6 @@ esxStorageVolLookupByPath(virConnectPtr conn, const cha= r *path) esxVI_ScsiLun *scsiLunList =3D NULL; esxVI_ScsiLun *scsiLun; esxVI_HostScsiDisk *hostScsiDisk =3D NULL; - char *poolName =3D NULL; /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; char uuid_string[VIR_UUID_STRING_BUFLEN] =3D ""; @@ -503,11 +502,12 @@ esxStorageVolLookupByPath(virConnectPtr conn, const c= har *path) goto cleanup; =20 for (scsiLun =3D scsiLunList; scsiLun; scsiLun =3D scsiLun->_next) { + g_autofree char *poolName =3D NULL; + hostScsiDisk =3D esxVI_HostScsiDisk_DynamicCast(scsiLun); =20 if (hostScsiDisk && STREQ(hostScsiDisk->devicePath, path)) { /* Found matching device */ - VIR_FREE(poolName); =20 if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary, hostScsiDisk->key, @@ -527,8 +527,6 @@ esxStorageVolLookupByPath(virConnectPtr conn, const cha= r *path) =20 cleanup: esxVI_ScsiLun_Free(&scsiLunList); - VIR_FREE(poolName); - return volume; } =20 @@ -539,7 +537,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) { virStorageVolPtr volume =3D NULL; esxPrivate *priv =3D conn->privateData; - char *poolName =3D NULL; esxVI_ScsiLun *scsiLunList =3D NULL; esxVI_ScsiLun *scsiLun; /* VIR_CRYPTO_HASH_SIZE_MD5 =3D VIR_UUID_BUFLEN =3D 16 */ @@ -555,6 +552,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) =20 for (scsiLun =3D scsiLunList; scsiLun; scsiLun =3D scsiLun->_next) { + g_autofree char *poolName =3D NULL; + memset(uuid_string, '\0', sizeof(uuid_string)); memset(md5, '\0', sizeof(md5)); =20 @@ -564,7 +563,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) =20 if (STREQ(key, uuid_string)) { /* Found matching UUID */ - VIR_FREE(poolName); =20 if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary, scsiLun->key, @@ -581,8 +579,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) =20 cleanup: esxVI_ScsiLun_Free(&scsiLunList); - VIR_FREE(poolName); - return volume; } =20 diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index 9466ec81cb..63959ec237 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -598,7 +598,6 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char = **const names, esxVI_HostDatastoreBrowserSearchResults *searchResultsList =3D NULL; esxVI_HostDatastoreBrowserSearchResults *searchResults =3D NULL; esxVI_FileInfo *fileInfo =3D NULL; - char *directoryAndFileName =3D NULL; size_t length; int count =3D 0; size_t i; @@ -619,7 +618,7 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char = **const names, /* Interpret search result */ for (searchResults =3D searchResultsList; searchResults; searchResults =3D searchResults->_next) { - VIR_FREE(directoryAndFileName); + g_autofree char *directoryAndFileName =3D NULL; =20 if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NU= LL, &directoryAndFileName) < 0) { @@ -659,8 +658,6 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char = **const names, } =20 esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList); - VIR_FREE(directoryAndFileName); - return count; } =20 @@ -730,12 +727,9 @@ esxStorageVolLookupByKey(virConnectPtr conn, const cha= r *key) char *datastoreName =3D NULL; esxVI_HostDatastoreBrowserSearchResults *searchResultsList =3D NULL; esxVI_HostDatastoreBrowserSearchResults *searchResults =3D NULL; - char *directoryAndFileName =3D NULL; size_t length; - char *datastorePath =3D NULL; char *volumeName =3D NULL; esxVI_FileInfo *fileInfo =3D NULL; - char *uuid_string =3D NULL; char key_candidate[VIR_UUID_STRING_BUFLEN] =3D ""; =20 if (STRPREFIX(key, "[")) { @@ -777,7 +771,7 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) /* Interpret search result */ for (searchResults =3D searchResultsList; searchResults; searchResults =3D searchResults->_next) { - VIR_FREE(directoryAndFileName); + g_autofree char *directoryAndFileName =3D NULL; =20 if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NULL, &directoryAndFileName) < = 0) { @@ -795,7 +789,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) /* Build datastore path and query the UUID */ for (fileInfo =3D searchResults->file; fileInfo; fileInfo =3D fileInfo->_next) { - VIR_FREE(datastorePath); + g_autofree char *datastorePath =3D NULL; + g_autofree char *uuid_string =3D NULL; =20 if (length < 1) { volumeName =3D g_strdup(fileInfo->path); @@ -811,8 +806,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char= *key) continue; } =20 - VIR_FREE(uuid_string); - if (esxVI_QueryVirtualDiskUuid (priv->primary, datastorePath, priv->primary->datacenter->_reference, @@ -838,10 +831,7 @@ esxStorageVolLookupByKey(virConnectPtr conn, const cha= r *key) esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&datastoreList); esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList); - VIR_FREE(directoryAndFileName); - VIR_FREE(datastorePath); VIR_FREE(volumeName); - VIR_FREE(uuid_string); =20 return volume; } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 7ff43adaaf..987259be4b 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -2761,7 +2761,6 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, = const char *name, esxVI_String *completePropertyNameList =3D NULL; esxVI_ObjectContent *virtualMachineList =3D NULL; esxVI_ObjectContent *candidate =3D NULL; - char *name_candidate =3D NULL; =20 ESX_VI_CHECK_ARG_LIST(virtualMachine); =20 @@ -2775,7 +2774,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, = const char *name, =20 for (candidate =3D virtualMachineList; candidate; candidate =3D candidate->_next) { - VIR_FREE(name_candidate); + g_autofree char *name_candidate =3D NULL; =20 if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candida= te, NULL) < 0) { @@ -2802,8 +2801,6 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, = const char *name, cleanup: esxVI_String_Free(&completePropertyNameList); esxVI_ObjectContent_Free(&virtualMachineList); - VIR_FREE(name_candidate); - return result; } =20 --=20 2.29.2