From 5140f97bcc3c1cffcf3a088e1273c1857b5903d6 Mon Sep 17 00:00:00 2001 From: Matt Coleman Date: Wed, 21 Oct 2020 04:46:05 -0400 Subject: [PATCH] hyperv: enable usage of g_autoptr for hypervInvokeParamsList Signed-off-by: Matt Coleman Reviewed-by: Michal Privoznik --- src/hyperv/hyperv_driver.c | 14 +++++--------- src/hyperv/hyperv_wmi.c | 3 +-- src/hyperv/hyperv_wmi.h | 1 + 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 9ec2b879fc..8f0cccdacd 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1619,7 +1619,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, Msvm_ComputerSystem *computerSystem = NULL; Msvm_Keyboard *keyboard = NULL; g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER; - hypervInvokeParamsListPtr params = NULL; + g_autoptr(hypervInvokeParamsList) params = NULL; char keycodeStr[VIR_INT64_STR_BUFLEN]; virCheckFlags(0, -1); @@ -1672,10 +1672,8 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, goto cleanup; } - if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) { - hypervFreeInvokeParams(params); + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) goto cleanup; - } if (hypervInvokeMethod(priv, ¶ms, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key %d"), @@ -1699,10 +1697,8 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, goto cleanup; } - if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) { - hypervFreeInvokeParams(params); + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) goto cleanup; - } if (hypervInvokeMethod(priv, ¶ms, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not release key %s"), @@ -1730,7 +1726,7 @@ hypervDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory, char uuid_string[VIR_UUID_STRING_BUFLEN]; hypervPrivate *priv = domain->conn->privateData; char *memory_str = NULL; - hypervInvokeParamsListPtr params = NULL; + g_autoptr(hypervInvokeParamsList) params = NULL; unsigned long memory_mb = VIR_ROUND_UP(VIR_DIV_UP(memory, 1024), 2); Msvm_VirtualSystemSettingData *vssd = NULL; Msvm_MemorySettingData *memsd = NULL; @@ -1814,7 +1810,7 @@ hypervDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory, VIR_FREE(memory_str); hypervFreeObject(priv, (hypervObject *)vssd); hypervFreeObject(priv, (hypervObject *)memsd); - hypervFreeInvokeParams(params); + return result; } diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 8bebf02a50..29447b8f0f 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -788,7 +788,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr *paramsPtr, WsXmlDocH *res) { - hypervInvokeParamsListPtr params = *paramsPtr; + g_autoptr(hypervInvokeParamsList) params = *paramsPtr; int result = -1; size_t i = 0; int returnCode; @@ -963,7 +963,6 @@ hypervInvokeMethod(hypervPrivate *priv, VIR_FREE(returnValue); VIR_FREE(instanceID); hypervFreeObject(priv, (hypervObject *)job); - hypervFreeInvokeParams(params); *paramsPtr = NULL; return result; } diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index fa8e48a70e..3a623e99fa 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -135,6 +135,7 @@ hypervInvokeParamsListPtr hypervCreateInvokeParamsList(hypervPrivate *priv, const char *method, const char *selector, hypervWmiClassInfoListPtr obj); void hypervFreeInvokeParams(hypervInvokeParamsListPtr params); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(hypervInvokeParamsList, hypervFreeInvokeParams); int hypervAddSimpleParam(hypervInvokeParamsListPtr params, const char *name, const char *value);