[PATCH v3 1/9] hyperv: enable usage of g_autoptr for hypervInvokeParamsList

Matt Coleman mcoleman at datto.com
Wed Oct 21 08:46:05 UTC 2020


Signed-off-by: Matt Coleman <matt at datto.com>
---
 src/hyperv/hyperv_driver.c | 14 +++++---------
 src/hyperv/hyperv_wmi.h    |  1 +
 2 files changed, 6 insertions(+), 9 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, &params, 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, &params, 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.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);
-- 
2.27.0





More information about the libvir-list mailing list