[PATCH 1/5] hyperv: Make it obvious that hypervInvokeMethod() consumes an argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Upon invocation, hypervInvokeMethod() consumes passed @params
(the second argument) regardless whether success or failure is
released. However, it takes only simple pointer (which hides this
ownership transfer) and because of that it doesn't clear it.

Switch to double pointer and tweak the documentation.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/hyperv/hyperv_driver.c |  6 +++---
 src/hyperv/hyperv_wmi.c    | 20 ++++++++++++++------
 src/hyperv/hyperv_wmi.h    |  5 +++--
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 2ac30fa4c6..eeb65bd4d7 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1677,7 +1677,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
             goto cleanup;
         }
 
-        if (hypervInvokeMethod(priv, params, NULL) < 0) {
+        if (hypervInvokeMethod(priv, &params, NULL) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key %d"),
                            translatedKeycodes[i]);
             goto cleanup;
@@ -1704,7 +1704,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
             goto cleanup;
         }
 
-        if (hypervInvokeMethod(priv, params, NULL) < 0) {
+        if (hypervInvokeMethod(priv, &params, NULL) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not release key %s"),
                     keycodeStr);
             goto cleanup;
@@ -1807,7 +1807,7 @@ hypervDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory,
         }
     }
 
-    if (hypervInvokeMethod(priv, params, NULL) < 0) {
+    if (hypervInvokeMethod(priv, &params, NULL) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not set memory"));
         goto cleanup;
     }
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 2b40e72053..78d15e2a43 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -753,17 +753,24 @@ hypervSerializeEmbeddedParam(hypervParamPtr p, const char *resourceUri,
 /*
  * hypervInvokeMethod:
  * @priv: hypervPrivate object associated with the connection
- * @params: object containing the all necessary information for method
- * invocation
+ * @paramsPtr: pointer to object containing the all necessary information for
+ *             method invocation (consumed on invocation)
  * @res: Optional out parameter to contain the response XML.
  *
- * Performs an invocation described by @params, and optionally returns the
- * XML containing the result. Returns -1 on failure, 0 on success.
+ * Performs an invocation described by object at @paramsPtr, and optionally
+ * returns the XML containing the result.
+ *
+ * Please note that, object at @paramsPtr is consumed by this function and the
+ * pointer is cleared out, regardless of returning success or failure.
+ *
+ * Returns -1 on failure, 0 on success.
  */
 int
-hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params,
-        WsXmlDocH *res)
+hypervInvokeMethod(hypervPrivate *priv,
+                   hypervInvokeParamsListPtr *paramsPtr,
+                   WsXmlDocH *res)
 {
+    hypervInvokeParamsListPtr params = *paramsPtr;
     int result = -1;
     size_t i = 0;
     int returnCode;
@@ -939,6 +946,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params,
     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 ee16657768..20749f2a39 100644
--- a/src/hyperv/hyperv_wmi.h
+++ b/src/hyperv/hyperv_wmi.h
@@ -154,8 +154,9 @@ int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate *priv
 
 void hypervFreeEmbeddedParam(virHashTablePtr p);
 
-int hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params,
-        WsXmlDocH *res);
+int hypervInvokeMethod(hypervPrivate *priv,
+                       hypervInvokeParamsListPtr *paramsPtr,
+                       WsXmlDocH *res);
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * CIM/Msvm_ReturnCode
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux