mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
esx: use g_autofree when made possible by reducing scope
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 <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
213662813c
commit
22a370d8b1
@ -1391,7 +1391,6 @@ esxDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
esxVI_ObjectContent *virtualMachine = NULL;
|
esxVI_ObjectContent *virtualMachine = NULL;
|
||||||
esxVI_VirtualMachinePowerState powerState;
|
esxVI_VirtualMachinePowerState powerState;
|
||||||
int id_candidate = -1;
|
int id_candidate = -1;
|
||||||
char *name_candidate = NULL;
|
|
||||||
unsigned char uuid_candidate[VIR_UUID_BUFLEN];
|
unsigned char uuid_candidate[VIR_UUID_BUFLEN];
|
||||||
virDomainPtr domain = NULL;
|
virDomainPtr domain = NULL;
|
||||||
|
|
||||||
@ -1410,6 +1409,8 @@ esxDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
|
|
||||||
for (virtualMachine = virtualMachineList; virtualMachine;
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
||||||
virtualMachine = virtualMachine->_next) {
|
virtualMachine = virtualMachine->_next) {
|
||||||
|
g_autofree char *name_candidate = NULL;
|
||||||
|
|
||||||
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
if (esxVI_GetVirtualMachinePowerState(virtualMachine,
|
||||||
&powerState) < 0) {
|
&powerState) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1419,8 +1420,6 @@ esxDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
if (powerState == esxVI_VirtualMachinePowerState_PoweredOff)
|
if (powerState == esxVI_VirtualMachinePowerState_PoweredOff)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
VIR_FREE(name_candidate);
|
|
||||||
|
|
||||||
if (esxVI_GetVirtualMachineIdentity(virtualMachine,
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine,
|
||||||
&id_candidate, &name_candidate,
|
&id_candidate, &name_candidate,
|
||||||
uuid_candidate) < 0) {
|
uuid_candidate) < 0) {
|
||||||
@ -1444,8 +1443,6 @@ esxDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
cleanup:
|
cleanup:
|
||||||
esxVI_String_Free(&propertyNameList);
|
esxVI_String_Free(&propertyNameList);
|
||||||
esxVI_ObjectContent_Free(&virtualMachineList);
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
||||||
VIR_FREE(name_candidate);
|
|
||||||
|
|
||||||
return domain;
|
return domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4754,7 +4751,6 @@ esxConnectListAllDomains(virConnectPtr conn,
|
|||||||
esxVI_AutoStartPowerInfo *powerInfoList = NULL;
|
esxVI_AutoStartPowerInfo *powerInfoList = NULL;
|
||||||
esxVI_AutoStartPowerInfo *powerInfo = NULL;
|
esxVI_AutoStartPowerInfo *powerInfo = NULL;
|
||||||
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
esxVI_VirtualMachineSnapshotTree *rootSnapshotTreeList = NULL;
|
||||||
char *name = NULL;
|
|
||||||
int id;
|
int id;
|
||||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -4839,9 +4835,9 @@ esxConnectListAllDomains(virConnectPtr conn,
|
|||||||
|
|
||||||
for (virtualMachine = virtualMachineList; virtualMachine;
|
for (virtualMachine = virtualMachineList; virtualMachine;
|
||||||
virtualMachine = virtualMachine->_next) {
|
virtualMachine = virtualMachine->_next) {
|
||||||
if (needIdentity) {
|
g_autofree char *name = NULL;
|
||||||
VIR_FREE(name);
|
|
||||||
|
|
||||||
|
if (needIdentity) {
|
||||||
if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id,
|
if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id,
|
||||||
&name, uuid) < 0) {
|
&name, uuid) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -4959,7 +4955,6 @@ esxConnectListAllDomains(virConnectPtr conn,
|
|||||||
VIR_FREE(doms);
|
VIR_FREE(doms);
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(name);
|
|
||||||
esxVI_AutoStartDefaults_Free(&autoStartDefaults);
|
esxVI_AutoStartDefaults_Free(&autoStartDefaults);
|
||||||
esxVI_AutoStartPowerInfo_Free(&powerInfoList);
|
esxVI_AutoStartPowerInfo_Free(&powerInfoList);
|
||||||
esxVI_String_Free(&propertyNameList);
|
esxVI_String_Free(&propertyNameList);
|
||||||
|
@ -494,7 +494,6 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
|||||||
esxVI_ScsiLun *scsiLunList = NULL;
|
esxVI_ScsiLun *scsiLunList = NULL;
|
||||||
esxVI_ScsiLun *scsiLun;
|
esxVI_ScsiLun *scsiLun;
|
||||||
esxVI_HostScsiDisk *hostScsiDisk = NULL;
|
esxVI_HostScsiDisk *hostScsiDisk = NULL;
|
||||||
char *poolName = NULL;
|
|
||||||
/* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */
|
/* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */
|
||||||
unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5];
|
unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5];
|
||||||
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
|
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
|
||||||
@ -503,11 +502,12 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) {
|
for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) {
|
||||||
|
g_autofree char *poolName = NULL;
|
||||||
|
|
||||||
hostScsiDisk = esxVI_HostScsiDisk_DynamicCast(scsiLun);
|
hostScsiDisk = esxVI_HostScsiDisk_DynamicCast(scsiLun);
|
||||||
|
|
||||||
if (hostScsiDisk && STREQ(hostScsiDisk->devicePath, path)) {
|
if (hostScsiDisk && STREQ(hostScsiDisk->devicePath, path)) {
|
||||||
/* Found matching device */
|
/* Found matching device */
|
||||||
VIR_FREE(poolName);
|
|
||||||
|
|
||||||
if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary,
|
if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary,
|
||||||
hostScsiDisk->key,
|
hostScsiDisk->key,
|
||||||
@ -527,8 +527,6 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
esxVI_ScsiLun_Free(&scsiLunList);
|
esxVI_ScsiLun_Free(&scsiLunList);
|
||||||
VIR_FREE(poolName);
|
|
||||||
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,7 +537,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
{
|
{
|
||||||
virStorageVolPtr volume = NULL;
|
virStorageVolPtr volume = NULL;
|
||||||
esxPrivate *priv = conn->privateData;
|
esxPrivate *priv = conn->privateData;
|
||||||
char *poolName = NULL;
|
|
||||||
esxVI_ScsiLun *scsiLunList = NULL;
|
esxVI_ScsiLun *scsiLunList = NULL;
|
||||||
esxVI_ScsiLun *scsiLun;
|
esxVI_ScsiLun *scsiLun;
|
||||||
/* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */
|
/* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */
|
||||||
@ -555,6 +552,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
|
|
||||||
for (scsiLun = scsiLunList; scsiLun;
|
for (scsiLun = scsiLunList; scsiLun;
|
||||||
scsiLun = scsiLun->_next) {
|
scsiLun = scsiLun->_next) {
|
||||||
|
g_autofree char *poolName = NULL;
|
||||||
|
|
||||||
memset(uuid_string, '\0', sizeof(uuid_string));
|
memset(uuid_string, '\0', sizeof(uuid_string));
|
||||||
memset(md5, '\0', sizeof(md5));
|
memset(md5, '\0', sizeof(md5));
|
||||||
|
|
||||||
@ -564,7 +563,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
|
|
||||||
if (STREQ(key, uuid_string)) {
|
if (STREQ(key, uuid_string)) {
|
||||||
/* Found matching UUID */
|
/* Found matching UUID */
|
||||||
VIR_FREE(poolName);
|
|
||||||
|
|
||||||
if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary,
|
if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary,
|
||||||
scsiLun->key,
|
scsiLun->key,
|
||||||
@ -581,8 +579,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
esxVI_ScsiLun_Free(&scsiLunList);
|
esxVI_ScsiLun_Free(&scsiLunList);
|
||||||
VIR_FREE(poolName);
|
|
||||||
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +598,6 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
|
|||||||
esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL;
|
esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL;
|
||||||
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
||||||
esxVI_FileInfo *fileInfo = NULL;
|
esxVI_FileInfo *fileInfo = NULL;
|
||||||
char *directoryAndFileName = NULL;
|
|
||||||
size_t length;
|
size_t length;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -619,7 +618,7 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
|
|||||||
/* Interpret search result */
|
/* Interpret search result */
|
||||||
for (searchResults = searchResultsList; searchResults;
|
for (searchResults = searchResultsList; searchResults;
|
||||||
searchResults = searchResults->_next) {
|
searchResults = searchResults->_next) {
|
||||||
VIR_FREE(directoryAndFileName);
|
g_autofree char *directoryAndFileName = NULL;
|
||||||
|
|
||||||
if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NULL,
|
if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL, NULL,
|
||||||
&directoryAndFileName) < 0) {
|
&directoryAndFileName) < 0) {
|
||||||
@ -659,8 +658,6 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
|
|||||||
}
|
}
|
||||||
|
|
||||||
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList);
|
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList);
|
||||||
VIR_FREE(directoryAndFileName);
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,12 +727,9 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
char *datastoreName = NULL;
|
char *datastoreName = NULL;
|
||||||
esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL;
|
esxVI_HostDatastoreBrowserSearchResults *searchResultsList = NULL;
|
||||||
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
|
||||||
char *directoryAndFileName = NULL;
|
|
||||||
size_t length;
|
size_t length;
|
||||||
char *datastorePath = NULL;
|
|
||||||
char *volumeName = NULL;
|
char *volumeName = NULL;
|
||||||
esxVI_FileInfo *fileInfo = NULL;
|
esxVI_FileInfo *fileInfo = NULL;
|
||||||
char *uuid_string = NULL;
|
|
||||||
char key_candidate[VIR_UUID_STRING_BUFLEN] = "";
|
char key_candidate[VIR_UUID_STRING_BUFLEN] = "";
|
||||||
|
|
||||||
if (STRPREFIX(key, "[")) {
|
if (STRPREFIX(key, "[")) {
|
||||||
@ -777,7 +771,7 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
/* Interpret search result */
|
/* Interpret search result */
|
||||||
for (searchResults = searchResultsList; searchResults;
|
for (searchResults = searchResultsList; searchResults;
|
||||||
searchResults = searchResults->_next) {
|
searchResults = searchResults->_next) {
|
||||||
VIR_FREE(directoryAndFileName);
|
g_autofree char *directoryAndFileName = NULL;
|
||||||
|
|
||||||
if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL,
|
if (esxUtil_ParseDatastorePath(searchResults->folderPath, NULL,
|
||||||
NULL, &directoryAndFileName) < 0) {
|
NULL, &directoryAndFileName) < 0) {
|
||||||
@ -795,7 +789,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
/* Build datastore path and query the UUID */
|
/* Build datastore path and query the UUID */
|
||||||
for (fileInfo = searchResults->file; fileInfo;
|
for (fileInfo = searchResults->file; fileInfo;
|
||||||
fileInfo = fileInfo->_next) {
|
fileInfo = fileInfo->_next) {
|
||||||
VIR_FREE(datastorePath);
|
g_autofree char *datastorePath = NULL;
|
||||||
|
g_autofree char *uuid_string = NULL;
|
||||||
|
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
volumeName = g_strdup(fileInfo->path);
|
volumeName = g_strdup(fileInfo->path);
|
||||||
@ -811,8 +806,6 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(uuid_string);
|
|
||||||
|
|
||||||
if (esxVI_QueryVirtualDiskUuid
|
if (esxVI_QueryVirtualDiskUuid
|
||||||
(priv->primary, datastorePath,
|
(priv->primary, datastorePath,
|
||||||
priv->primary->datacenter->_reference,
|
priv->primary->datacenter->_reference,
|
||||||
@ -838,10 +831,7 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
esxVI_String_Free(&propertyNameList);
|
esxVI_String_Free(&propertyNameList);
|
||||||
esxVI_ObjectContent_Free(&datastoreList);
|
esxVI_ObjectContent_Free(&datastoreList);
|
||||||
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList);
|
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResultsList);
|
||||||
VIR_FREE(directoryAndFileName);
|
|
||||||
VIR_FREE(datastorePath);
|
|
||||||
VIR_FREE(volumeName);
|
VIR_FREE(volumeName);
|
||||||
VIR_FREE(uuid_string);
|
|
||||||
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
@ -2761,7 +2761,6 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
|
|||||||
esxVI_String *completePropertyNameList = NULL;
|
esxVI_String *completePropertyNameList = NULL;
|
||||||
esxVI_ObjectContent *virtualMachineList = NULL;
|
esxVI_ObjectContent *virtualMachineList = NULL;
|
||||||
esxVI_ObjectContent *candidate = NULL;
|
esxVI_ObjectContent *candidate = NULL;
|
||||||
char *name_candidate = NULL;
|
|
||||||
|
|
||||||
ESX_VI_CHECK_ARG_LIST(virtualMachine);
|
ESX_VI_CHECK_ARG_LIST(virtualMachine);
|
||||||
|
|
||||||
@ -2775,7 +2774,7 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
|
|||||||
|
|
||||||
for (candidate = virtualMachineList; candidate;
|
for (candidate = virtualMachineList; candidate;
|
||||||
candidate = candidate->_next) {
|
candidate = candidate->_next) {
|
||||||
VIR_FREE(name_candidate);
|
g_autofree char *name_candidate = NULL;
|
||||||
|
|
||||||
if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
|
if (esxVI_GetVirtualMachineIdentity(candidate, NULL, &name_candidate,
|
||||||
NULL) < 0) {
|
NULL) < 0) {
|
||||||
@ -2802,8 +2801,6 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name,
|
|||||||
cleanup:
|
cleanup:
|
||||||
esxVI_String_Free(&completePropertyNameList);
|
esxVI_String_Free(&completePropertyNameList);
|
||||||
esxVI_ObjectContent_Free(&virtualMachineList);
|
esxVI_ObjectContent_Free(&virtualMachineList);
|
||||||
VIR_FREE(name_candidate);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user