Signed-off-by: Laine Stump <laine(a)redhat.com>
---
src/esx/esx_driver.c | 19 +++++--------------
src/esx/esx_util.c | 4 ++--
src/esx/esx_vi.c | 19 +++++--------------
src/esx/esx_vi_methods.c | 6 +-----
4 files changed, 13 insertions(+), 35 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 0ede65279a..3fb7a3b62c 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -275,7 +275,7 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
esxVI_ObjectContent *datastore = NULL;
esxVI_DatastoreHostMount *hostMount = NULL;
char separator = '/';
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
char *tmp;
size_t length;
@@ -336,10 +336,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
success = true;
cleanup:
- if (! success) {
- virBufferFreeAndReset(&buffer);
+ if (! success)
VIR_FREE(result);
- }
VIR_FREE(datastoreName);
VIR_FREE(directoryAndFileName);
@@ -2359,7 +2357,7 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream,
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_VirtualMachinePowerState powerState;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
char *url = NULL;
virCheckFlags(0, NULL);
@@ -2413,7 +2411,6 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream,
}
cleanup:
- virBufferFreeAndReset(&buffer);
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
@@ -2579,7 +2576,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
char *datastoreName = NULL;
char *directoryName = NULL;
char *directoryAndFileName = NULL;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
char *url = NULL;
char *vmx = NULL;
virVMXContext ctx;
@@ -2653,9 +2650,6 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
}
cleanup:
- if (!url)
- virBufferFreeAndReset(&buffer);
-
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&virtualMachine);
VIR_FREE(moref);
@@ -2936,7 +2930,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags)
char *datastoreName = NULL;
char *directoryName = NULL;
char *escapedName = NULL;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
char *url = NULL;
char *datastoreRelatedPath = NULL;
esxVI_String *propertyNameList = NULL;
@@ -3124,9 +3118,6 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags)
/* FIXME: Add proper rollback in case of an error */
cleanup:
- if (!url)
- virBufferFreeAndReset(&buffer);
-
virDomainDefFree(def);
VIR_FREE(vmx);
VIR_FREE(datastoreName);
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 89d136248f..11f43acc19 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -357,7 +357,7 @@ esxUtil_EscapeBase64(const char *string)
static const char *base64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
const char *tmp1 = string;
size_t length;
unsigned char c1, c2, c3;
@@ -456,7 +456,7 @@ esxUtil_EscapeDatastoreItem(const char *string)
char *
esxUtil_EscapeForXml(const char *string)
{
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
virBufferEscapeString(&buffer, "%s", string);
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 16690edfbe..d48a24e9d3 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -370,7 +370,7 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char
**content,
unsigned long long offset, unsigned long long *length)
{
char *range = NULL;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
int responseCode = 0;
ESX_VI_CHECK_ARG_LIST(content);
@@ -421,10 +421,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char
**content,
cleanup:
VIR_FREE(range);
- if (!(*content)) {
- virBufferFreeAndReset(&buffer);
+ if (!(*content))
return -1;
- }
return 0;
}
@@ -1025,7 +1023,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const
char *path)
char *saveptr = NULL;
char *previousItem = NULL;
char *item = NULL;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
esxVI_ManagedObjectReference *root = NULL;
esxVI_Folder *folder = NULL;
@@ -1184,9 +1182,6 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const
char *path)
result = 0;
cleanup:
- if (result < 0)
- virBufferFreeAndReset(&buffer);
-
if (root != ctx->service->rootFolder &&
(!ctx->datacenter || root != ctx->datacenter->hostFolder)) {
esxVI_ManagedObjectReference_Free(&root);
@@ -1248,7 +1243,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
esxVI_Occurrence occurrence)
{
int result = -1;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL;
char *xpathExpression = NULL;
xmlXPathContextPtr xpathContext = NULL;
@@ -1408,7 +1403,6 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
cleanup:
if (result < 0) {
- virBufferFreeAndReset(&buffer);
esxVI_Response_Free(response);
esxVI_Fault_Free(&fault);
}
@@ -4130,7 +4124,7 @@ esxVI_HandleVirtualMachineQuestion
{
int result = -1;
esxVI_ElementDescription *elementDescription = NULL;
- virBuffer buffer = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
esxVI_ElementDescription *answerChoice = NULL;
int answerIndex = 0;
char *possibleAnswers = NULL;
@@ -4212,9 +4206,6 @@ esxVI_HandleVirtualMachineQuestion
result = 0;
cleanup:
- if (result < 0)
- virBufferFreeAndReset(&buffer);
-
VIR_FREE(possibleAnswers);
return result;
diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c
index 616b202d09..e22a078997 100644
--- a/src/esx/esx_vi_methods.c
+++ b/src/esx/esx_vi_methods.c
@@ -105,7 +105,7 @@
{ \
int result = -1; \
const char *methodName = #_name; \
- virBuffer buffer = VIR_BUFFER_INITIALIZER; \
+ g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER; \
char *request = NULL; \
esxVI_Response *response = NULL; \
\
@@ -136,10 +136,6 @@
result = 0; \
\
cleanup: \
- if (result < 0) { \
- virBufferFreeAndReset(&buffer); \
- } \
- \
VIR_FREE(request); \
esxVI_Response_Free(&response); \
\
--
2.25.4