All of these strings are allocated once, freed once, and are never
returned out of the function where they are created, used, and are
freed.
Signed-off-by: Laine Stump <laine(a)redhat.com>
---
src/esx/esx_driver.c | 128 +++++++++--------------------
src/esx/esx_storage_backend_vmfs.c | 102 ++++++++---------------
src/esx/esx_stream.c | 7 +-
src/esx/esx_util.c | 11 +--
src/esx/esx_vi.c | 53 ++++--------
src/esx/esx_vi_methods.c | 3 +-
src/esx/esx_vi_types.c | 8 +-
7 files changed, 93 insertions(+), 219 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 0271f81a56..df257341b8 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -139,8 +139,8 @@ esxParseVMXFileName(const char *fileName,
char *datastoreName;
char *tmp;
char *saveptr;
- char *strippedFileName = NULL;
- char *copyOfFileName = NULL;
+ g_autofree char *strippedFileName = NULL;
+ g_autofree char *copyOfFileName = NULL;
char *directoryAndFileName;
int ret = -1;
@@ -253,8 +253,6 @@ esxParseVMXFileName(const char *fileName,
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datastoreList);
esxVI_DatastoreHostMount_Free(&hostMount);
- VIR_FREE(strippedFileName);
- VIR_FREE(copyOfFileName);
return ret;
}
@@ -280,8 +278,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
bool success = false;
char *result = NULL;
esxVMX_Data *data = opaque;
- char *datastoreName = NULL;
- char *directoryAndFileName = NULL;
+ g_autofree char *datastoreName = NULL;
+ g_autofree char *directoryAndFileName = NULL;
esxVI_ObjectContent *datastore = NULL;
esxVI_DatastoreHostMount *hostMount = NULL;
char separator = '/';
@@ -349,8 +347,6 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
if (! success)
VIR_FREE(result);
- VIR_FREE(datastoreName);
- VIR_FREE(directoryAndFileName);
esxVI_ObjectContent_Free(&datastore);
esxVI_DatastoreHostMount_Free(&hostMount);
@@ -613,9 +609,9 @@ esxConnectToHost(esxPrivate *priv,
{
int result = -1;
g_autofree char *ipAddress = NULL;
- char *username = NULL;
- char *password = NULL;
- char *url = NULL;
+ g_autofree char *username = NULL;
+ g_autofree char *password = NULL;
+ g_autofree char *url = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL;
esxVI_Boolean inMaintenanceMode = esxVI_Boolean_Undefined;
@@ -683,9 +679,6 @@ esxConnectToHost(esxPrivate *priv,
result = 0;
cleanup:
- VIR_FREE(username);
- VIR_FREE(password);
- VIR_FREE(url);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
@@ -703,9 +696,9 @@ esxConnectToVCenter(esxPrivate *priv,
{
int result = -1;
g_autofree char *ipAddress = NULL;
- char *username = NULL;
- char *password = NULL;
- char *url = NULL;
+ g_autofree char *username = NULL;
+ g_autofree char *password = NULL;
+ g_autofree char *url = NULL;
if (!hostSystemIPAddress &&
(!priv->parsedUri->path || STREQ(priv->parsedUri->path,
"/"))) {
@@ -761,10 +754,6 @@ esxConnectToVCenter(esxPrivate *priv,
result = 0;
cleanup:
- VIR_FREE(username);
- VIR_FREE(password);
- VIR_FREE(url);
-
return result;
}
@@ -822,7 +811,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
{
virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
esxPrivate *priv = NULL;
- char *potentialVCenterIPAddress = NULL;
+ g_autofree char *potentialVCenterIPAddress = NULL;
g_autofree char *vCenterIPAddress = NULL;
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
@@ -938,8 +927,6 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
cleanup:
esxFreePrivate(&priv);
- VIR_FREE(potentialVCenterIPAddress);
-
return result;
}
@@ -1472,7 +1459,7 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char
*uuid)
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachinePowerState powerState;
int id = -1;
- char *name = NULL;
+ g_autofree char *name = NULL;
virDomainPtr domain = NULL;
if (esxVI_EnsureSession(priv->primary) < 0)
@@ -1498,8 +1485,6 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char
*uuid)
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
- VIR_FREE(name);
-
return domain;
}
@@ -1559,7 +1544,7 @@ esxDomainSuspend(virDomainPtr domain)
esxVI_VirtualMachinePowerState powerState;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
@@ -1599,8 +1584,6 @@ esxDomainSuspend(virDomainPtr domain)
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -1616,7 +1599,7 @@ esxDomainResume(virDomainPtr domain)
esxVI_VirtualMachinePowerState powerState;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
@@ -1656,8 +1639,6 @@ esxDomainResume(virDomainPtr domain)
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -1767,7 +1748,7 @@ esxDomainDestroyFlags(virDomainPtr domain,
esxVI_VirtualMachinePowerState powerState;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(0, -1);
@@ -1816,8 +1797,6 @@ esxDomainDestroyFlags(virDomainPtr domain,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -1902,7 +1881,7 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
esxVI_VirtualMachineConfigSpec *spec = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
if (esxVI_EnsureSession(priv->primary) < 0)
return -1;
@@ -1954,8 +1933,6 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -1972,7 +1949,7 @@ esxDomainSetMemoryFlags(virDomainPtr domain,
esxVI_VirtualMachineConfigSpec *spec = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(0, -1);
@@ -2013,8 +1990,6 @@ esxDomainSetMemoryFlags(virDomainPtr domain,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -2434,7 +2409,7 @@ esxDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,
esxVI_VirtualMachineConfigSpec *spec = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE, -1);
@@ -2492,8 +2467,6 @@ esxDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -2574,14 +2547,14 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachinePowerState powerState;
int id;
- char *moref = NULL;
+ g_autofree char *moref = NULL;
char *vmPathName = NULL;
- char *datastoreName = NULL;
- char *directoryName = NULL;
- char *directoryAndFileName = NULL;
+ g_autofree char *datastoreName = NULL;
+ g_autofree char *directoryName = NULL;
+ g_autofree char *directoryAndFileName = NULL;
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
- char *url = NULL;
- char *vmx = NULL;
+ g_autofree char *url = NULL;
+ g_autofree char *vmx = NULL;
virVMXContext ctx;
esxVMX_Data data;
virDomainDefPtr def = NULL;
@@ -2655,13 +2628,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
- VIR_FREE(moref);
- VIR_FREE(datastoreName);
- VIR_FREE(directoryName);
- VIR_FREE(directoryAndFileName);
- VIR_FREE(url);
VIR_FREE(data.datastorePathWithoutFileName);
- VIR_FREE(vmx);
virDomainDefFree(def);
return xml;
@@ -2858,7 +2825,7 @@ esxDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
int id = -1;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(0, -1);
@@ -2903,7 +2870,6 @@ esxDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
return result;
}
@@ -2923,25 +2889,25 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags)
{
esxPrivate *priv = conn->privateData;
virDomainDefPtr def = NULL;
- char *vmx = NULL;
+ g_autofree char *vmx = NULL;
size_t i;
virDomainDiskDefPtr disk = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
int virtualHW_version;
virVMXContext ctx;
esxVMX_Data data;
- char *datastoreName = NULL;
- char *directoryName = NULL;
- char *escapedName = NULL;
+ g_autofree char *datastoreName = NULL;
+ g_autofree char *directoryName = NULL;
+ g_autofree char *escapedName = NULL;
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
- char *url = NULL;
+ g_autofree char *url = NULL;
char *datastoreRelatedPath = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL;
esxVI_ManagedObjectReference *resourcePool = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virDomainPtr domain = NULL;
const char *src;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
@@ -3122,19 +3088,11 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags)
cleanup:
virDomainDefFree(def);
- VIR_FREE(vmx);
- VIR_FREE(datastoreName);
- VIR_FREE(directoryName);
- VIR_FREE(escapedName);
- VIR_FREE(url);
- VIR_FREE(datastoreRelatedPath);
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
esxVI_ManagedObjectReference_Free(&resourcePool);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return domain;
}
@@ -3554,7 +3512,7 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
esxVI_SharesInfo *sharesInfo = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
size_t i;
virCheckFlags(0, -1);
@@ -3670,8 +3628,6 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -3735,7 +3691,7 @@ esxDomainMigratePerform(virDomainPtr domain,
esxVI_Event *eventList = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(ESX_MIGRATION_FLAGS, -1);
@@ -3850,8 +3806,6 @@ esxDomainMigratePerform(virDomainPtr domain,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_Event_Free(&eventList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -4049,7 +4003,7 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char
*xmlDesc,
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virDomainSnapshotPtr snapshot = NULL;
bool diskOnly = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) != 0;
bool quiesce = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE) != 0;
@@ -4122,8 +4076,6 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char
*xmlDesc,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return snapshot;
}
@@ -4563,7 +4515,7 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned
int flags)
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(0, -1);
@@ -4599,8 +4551,6 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned
int flags)
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -4616,7 +4566,7 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int
flags)
esxVI_Boolean removeChildren = esxVI_Boolean_False;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1);
@@ -4663,8 +4613,6 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int
flags)
cleanup:
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -4680,7 +4628,7 @@ esxDomainSetMemoryParameters(virDomainPtr domain,
virTypedParameterPtr params,
esxVI_VirtualMachineConfigSpec *spec = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
size_t i;
virCheckFlags(0, -1);
@@ -4733,8 +4681,6 @@ esxDomainSetMemoryParameters(virDomainPtr domain,
virTypedParameterPtr params,
esxVI_ObjectContent_Free(&virtualMachine);
esxVI_VirtualMachineConfigSpec_Free(&spec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c
index 27d8016194..9466ec81cb 100644
--- a/src/esx/esx_storage_backend_vmfs.c
+++ b/src/esx/esx_storage_backend_vmfs.c
@@ -672,8 +672,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
{
virStorageVolPtr volume = NULL;
esxPrivate *priv = pool->conn->privateData;
- char *datastorePath = NULL;
- char *key = NULL;
+ g_autofree char *datastorePath = NULL;
+ g_autofree char *key = NULL;
datastorePath = g_strdup_printf("[%s] %s", pool->name, name);
@@ -686,9 +686,6 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
&esxStorageBackendVMFS, NULL);
cleanup:
- VIR_FREE(datastorePath);
- VIR_FREE(key);
-
return volume;
}
@@ -699,9 +696,9 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
{
virStorageVolPtr volume = NULL;
esxPrivate *priv = conn->privateData;
- char *datastoreName = NULL;
- char *directoryAndFileName = NULL;
- char *key = NULL;
+ g_autofree char *datastoreName = NULL;
+ g_autofree char *directoryAndFileName = NULL;
+ g_autofree char *key = NULL;
if (esxUtil_ParseDatastorePath(path, &datastoreName, NULL,
&directoryAndFileName) < 0) {
@@ -717,10 +714,6 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
&esxStorageBackendVMFS, NULL);
cleanup:
- VIR_FREE(datastoreName);
- VIR_FREE(directoryAndFileName);
- VIR_FREE(key);
-
return volume;
}
@@ -864,20 +857,20 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
esxPrivate *priv = pool->conn->privateData;
virStoragePoolDef poolDef;
char *tmp;
- char *unescapedDatastorePath = NULL;
- char *unescapedDirectoryName = NULL;
- char *unescapedDirectoryAndFileName = NULL;
- char *directoryName = NULL;
- char *fileName = NULL;
- char *datastorePathWithoutFileName = NULL;
- char *datastorePath = NULL;
+ g_autofree char *unescapedDatastorePath = NULL;
+ g_autofree char *unescapedDirectoryName = NULL;
+ g_autofree char *unescapedDirectoryAndFileName = NULL;
+ g_autofree char *directoryName = NULL;
+ g_autofree char *fileName = NULL;
+ g_autofree char *datastorePathWithoutFileName = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_FileInfo *fileInfo = NULL;
esxVI_FileBackedVirtualDiskSpec *virtualDiskSpec = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
- char *uuid_string = NULL;
- char *key = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
+ g_autofree char *uuid_string = NULL;
+ g_autofree char *key = NULL;
g_autoptr(virStorageVolDef) def = NULL;
virCheckFlags(0, NULL);
@@ -1045,20 +1038,9 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
virtualDiskSpec->adapterType = NULL;
}
- VIR_FREE(unescapedDatastorePath);
- VIR_FREE(unescapedDirectoryName);
- VIR_FREE(unescapedDirectoryAndFileName);
- VIR_FREE(directoryName);
- VIR_FREE(fileName);
- VIR_FREE(datastorePathWithoutFileName);
- VIR_FREE(datastorePath);
esxVI_FileInfo_Free(&fileInfo);
esxVI_FileBackedVirtualDiskSpec_Free(&virtualDiskSpec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
- VIR_FREE(uuid_string);
- VIR_FREE(key);
-
return volume;
}
@@ -1073,21 +1055,21 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
virStorageVolPtr volume = NULL;
esxPrivate *priv = pool->conn->privateData;
virStoragePoolDef poolDef;
- char *sourceDatastorePath = NULL;
+ g_autofree char *sourceDatastorePath = NULL;
char *tmp;
- char *unescapedDatastorePath = NULL;
- char *unescapedDirectoryName = NULL;
- char *unescapedDirectoryAndFileName = NULL;
- char *directoryName = NULL;
- char *fileName = NULL;
- char *datastorePathWithoutFileName = NULL;
- char *datastorePath = NULL;
+ g_autofree char *unescapedDatastorePath = NULL;
+ g_autofree char *unescapedDirectoryName = NULL;
+ g_autofree char *unescapedDirectoryAndFileName = NULL;
+ g_autofree char *directoryName = NULL;
+ g_autofree char *fileName = NULL;
+ g_autofree char *datastorePathWithoutFileName = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_FileInfo *fileInfo = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
- char *uuid_string = NULL;
- char *key = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
+ g_autofree char *uuid_string = NULL;
+ g_autofree char *key = NULL;
g_autoptr(virStorageVolDef) def = NULL;
virCheckFlags(0, NULL);
@@ -1219,20 +1201,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
&esxStorageBackendVMFS, NULL);
cleanup:
- VIR_FREE(sourceDatastorePath);
- VIR_FREE(unescapedDatastorePath);
- VIR_FREE(unescapedDirectoryName);
- VIR_FREE(unescapedDirectoryAndFileName);
- VIR_FREE(directoryName);
- VIR_FREE(fileName);
- VIR_FREE(datastorePathWithoutFileName);
- VIR_FREE(datastorePath);
esxVI_FileInfo_Free(&fileInfo);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
- VIR_FREE(uuid_string);
- VIR_FREE(key);
-
return volume;
}
@@ -1243,10 +1213,10 @@ esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags)
{
int result = -1;
esxPrivate *priv = volume->conn->privateData;
- char *datastorePath = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(0, -1);
@@ -1271,10 +1241,7 @@ esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags)
result = 0;
cleanup:
- VIR_FREE(datastorePath);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -1285,10 +1252,10 @@ esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags)
{
int result = -1;
esxPrivate *priv = volume->conn->privateData;
- char *datastorePath = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
virCheckFlags(0, -1);
@@ -1313,10 +1280,7 @@ esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags)
result = 0;
cleanup:
- VIR_FREE(datastorePath);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
-
return result;
}
@@ -1328,7 +1292,7 @@ esxStorageVolGetInfo(virStorageVolPtr volume,
{
int result = -1;
esxPrivate *priv = volume->conn->privateData;
- char *datastorePath = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_FileInfo *fileInfo = NULL;
esxVI_VmDiskFileInfo *vmDiskFileInfo = NULL;
@@ -1358,7 +1322,6 @@ esxStorageVolGetInfo(virStorageVolPtr volume,
result = 0;
cleanup:
- VIR_FREE(datastorePath);
esxVI_FileInfo_Free(&fileInfo);
return result;
@@ -1372,7 +1335,7 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
{
esxPrivate *priv = volume->conn->privateData;
virStoragePoolDef pool;
- char *datastorePath = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_FileInfo *fileInfo = NULL;
esxVI_VmDiskFileInfo *vmDiskFileInfo = NULL;
esxVI_IsoImageFileInfo *isoImageFileInfo = NULL;
@@ -1438,7 +1401,6 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
xml = virStorageVolDefFormat(&pool, &def);
cleanup:
- VIR_FREE(datastorePath);
esxVI_FileInfo_Free(&fileInfo);
VIR_FREE(def.key);
diff --git a/src/esx/esx_stream.c b/src/esx/esx_stream.c
index 2e7f979e79..cc48c182d9 100644
--- a/src/esx/esx_stream.c
+++ b/src/esx/esx_stream.c
@@ -395,8 +395,8 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
{
int result = -1;
esxStreamPrivate *streamPriv;
- char *range = NULL;
- char *userpwd = NULL;
+ g_autofree char *range = NULL;
+ g_autofree char *userpwd = NULL;
esxVI_MultiCURL *multi = NULL;
/* FIXME: Although there is already some code in place to deal with
@@ -467,9 +467,6 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
esxFreeStreamPrivate(&streamPriv);
}
- VIR_FREE(range);
- VIR_FREE(userpwd);
-
return result;
}
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index d9e7641d67..64a2c968f0 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -207,7 +207,7 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char
**datastoreName,
char **directoryName, char **directoryAndFileName)
{
int result = -1;
- char *copyOfDatastorePath = NULL;
+ g_autofree char *copyOfDatastorePath = NULL;
char *tmp = NULL;
char *saveptr = NULL;
char *preliminaryDatastoreName = NULL;
@@ -270,8 +270,6 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char
**datastoreName,
VIR_FREE(*directoryAndFileName);
}
- VIR_FREE(copyOfDatastorePath);
-
return result;
}
@@ -429,8 +427,8 @@ esxUtil_ReplaceSpecialWindowsPathChars(char *string)
char *
esxUtil_EscapeDatastoreItem(const char *string)
{
- char *replaced;
- char *escaped1;
+ g_autofree char *replaced = NULL;
+ g_autofree char *escaped1 = NULL;
char *escaped2 = NULL;
replaced = g_strdup(string);
@@ -445,9 +443,6 @@ esxUtil_EscapeDatastoreItem(const char *string)
escaped2 = esxUtil_EscapeBase64(escaped1);
cleanup:
- VIR_FREE(replaced);
- VIR_FREE(escaped1);
-
return escaped2;
}
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 2eb8048858..7ff43adaaf 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -169,7 +169,7 @@ static int
esxVI_CURL_Debug(CURL *curl G_GNUC_UNUSED, curl_infotype type,
char *info, size_t size, void *userdata G_GNUC_UNUSED)
{
- char *buffer = NULL;
+ g_autofree char *buffer = NULL;
/*
* The libcurl documentation says:
@@ -221,8 +221,6 @@ esxVI_CURL_Debug(CURL *curl G_GNUC_UNUSED, curl_infotype type,
break;
}
- VIR_FREE(buffer);
-
return 0;
}
#endif
@@ -833,7 +831,7 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
const char *password, esxUtil_ParsedUri *parsedUri)
{
int result = -1;
- char *escapedPassword = NULL;
+ g_autofree char *escapedPassword = NULL;
if (!ctx || !url || !ipAddress || !username ||
!password || ctx->url || ctx->service || ctx->curl) {
@@ -965,8 +963,6 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url,
result = 0;
cleanup:
- VIR_FREE(escapedPassword);
-
return result;
}
@@ -1013,7 +1009,7 @@ int
esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
{
int result = -1;
- char *tmp = NULL;
+ g_autofree char *tmp = NULL;
char *saveptr = NULL;
char *previousItem = NULL;
char *item = NULL;
@@ -1181,7 +1177,6 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const
char *path)
esxVI_ManagedObjectReference_Free(&root);
}
- VIR_FREE(tmp);
esxVI_Folder_Free(&folder);
return result;
@@ -1239,7 +1234,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
int result = -1;
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL;
- char *xpathExpression = NULL;
+ g_autofree char *xpathExpression = NULL;
xmlXPathContextPtr xpathContext = NULL;
xmlNodePtr responseNode = NULL;
@@ -1401,7 +1396,6 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
esxVI_Fault_Free(&fault);
}
- VIR_FREE(xpathExpression);
xmlXPathFreeContext(xpathContext);
return result;
@@ -1509,7 +1503,7 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
{
size_t i;
int result = -1;
- char *name = NULL;
+ g_autofree char *name = NULL;
if (!value) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid
argument"));
@@ -1534,8 +1528,6 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration,
name, esxVI_Type_ToString(enumeration->type));
}
- VIR_FREE(name);
-
return result;
}
@@ -1895,7 +1887,7 @@ esxVI_EnsureSession(esxVI_Context *ctx)
esxVI_ObjectContent *sessionManager = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_UserSession *currentSession = NULL;
- char *escapedPassword = NULL;
+ g_autofree char *escapedPassword = NULL;
if (!ctx->sessionLock) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid call, no
mutex"));
@@ -1959,7 +1951,6 @@ esxVI_EnsureSession(esxVI_Context *ctx)
cleanup:
virMutexUnlock(ctx->sessionLock);
- VIR_FREE(escapedPassword);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&sessionManager);
esxVI_UserSession_Free(¤tSession);
@@ -3378,12 +3369,12 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
esxVI_Occurrence occurrence)
{
int result = -1;
- char *datastoreName = NULL;
- char *directoryName = NULL;
- char *directoryAndFileName = NULL;
- char *fileName = NULL;
+ g_autofree char *datastoreName = NULL;
+ g_autofree char *directoryName = NULL;
+ g_autofree char *directoryAndFileName = NULL;
+ g_autofree char *fileName = NULL;
size_t length;
- char *datastorePathWithoutFileName = NULL;
+ g_autofree char *datastorePathWithoutFileName = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *datastore = NULL;
esxVI_ManagedObjectReference *hostDatastoreBrowser = NULL;
@@ -3394,7 +3385,7 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
esxVI_FloppyImageFileQuery *floppyImageFileQuery = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
esxVI_TaskInfo *taskInfo = NULL;
esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
@@ -3544,17 +3535,11 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx,
if (searchSpec && searchSpec->matchPattern)
searchSpec->matchPattern->value = NULL;
- VIR_FREE(datastoreName);
- VIR_FREE(directoryName);
- VIR_FREE(directoryAndFileName);
- VIR_FREE(fileName);
- VIR_FREE(datastorePathWithoutFileName);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&datastore);
esxVI_ManagedObjectReference_Free(&hostDatastoreBrowser);
esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
esxVI_TaskInfo_Free(&taskInfo);
esxVI_HostDatastoreBrowserSearchResults_Free(&searchResults);
esxVI_FolderFileQuery_Free(&folderFileQuery);
@@ -3580,10 +3565,10 @@ esxVI_LookupDatastoreContentByDatastoreName
esxVI_VmDiskFileQuery *vmDiskFileQuery = NULL;
esxVI_IsoImageFileQuery *isoImageFileQuery = NULL;
esxVI_FloppyImageFileQuery *floppyImageFileQuery = NULL;
- char *datastorePath = NULL;
+ g_autofree char *datastorePath = NULL;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
- char *taskInfoErrorMessage = NULL;
+ g_autofree char *taskInfoErrorMessage = NULL;
esxVI_TaskInfo *taskInfo = NULL;
ESX_VI_CHECK_ARG_LIST(searchResultsList);
@@ -3672,9 +3657,7 @@ esxVI_LookupDatastoreContentByDatastoreName
esxVI_ObjectContent_Free(&datastore);
esxVI_ManagedObjectReference_Free(&hostDatastoreBrowser);
esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
- VIR_FREE(datastorePath);
esxVI_ManagedObjectReference_Free(&task);
- VIR_FREE(taskInfoErrorMessage);
esxVI_TaskInfo_Free(&taskInfo);
esxVI_VmDiskFileQuery_Free(&vmDiskFileQuery);
esxVI_IsoImageFileQuery_Free(&isoImageFileQuery);
@@ -3692,7 +3675,7 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
{
int result = -1;
esxVI_FileInfo *fileInfo = NULL;
- char *uuid_string = NULL;
+ g_autofree char *uuid_string = NULL;
ESX_VI_CHECK_ARG_LIST(key);
@@ -3727,8 +3710,6 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx,
cleanup:
esxVI_FileInfo_Free(&fileInfo);
- VIR_FREE(uuid_string);
-
return result;
}
@@ -4120,7 +4101,7 @@ esxVI_HandleVirtualMachineQuestion
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
esxVI_ElementDescription *answerChoice = NULL;
int answerIndex = 0;
- char *possibleAnswers = NULL;
+ g_autofree char *possibleAnswers = NULL;
if (!blocked) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid
argument"));
@@ -4199,8 +4180,6 @@ esxVI_HandleVirtualMachineQuestion
result = 0;
cleanup:
- VIR_FREE(possibleAnswers);
-
return result;
}
diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c
index e22a078997..87046b6225 100644
--- a/src/esx/esx_vi_methods.c
+++ b/src/esx/esx_vi_methods.c
@@ -106,7 +106,7 @@
int result = -1; \
const char *methodName = #_name; \
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER; \
- char *request = NULL; \
+ g_autofree char *request = NULL; \
esxVI_Response *response = NULL; \
\
ESX_VI__METHOD__PARAMETER__THIS__##_this_from_service \
@@ -136,7 +136,6 @@
result = 0; \
\
cleanup: \
- VIR_FREE(request); \
esxVI_Response_Free(&response); \
\
return result; \
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index 4d3617e0a8..1af075813e 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -330,7 +330,7 @@ VIR_LOG_INIT("esx.esx_vi_types");
esxVI_##_type##_Deserialize(xmlNodePtr node, esxVI_##_type **number) \
{ \
int result = -1; \
- char *string; \
+ g_autofree char *string = NULL; \
long long value; \
\
if (!number || *number) { \
@@ -374,8 +374,6 @@ VIR_LOG_INIT("esx.esx_vi_types");
if (result < 0) { \
esxVI_##_type##_Free(number); \
} \
- \
- VIR_FREE(string); \
\
return result; \
}
@@ -703,7 +701,7 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
esxVI_Type *actualType)
{
int result = -1;
- char *type = NULL;
+ g_autofree char *type = NULL;
if (!actualType || *actualType != esxVI_Type_Undefined) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid
argument"));
@@ -732,8 +730,6 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
result = 0;
cleanup:
- VIR_FREE(type);
-
return result;
}
--
2.29.2