]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: Make it obvious that hypervInvokeMethod() consumes an argument
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 15 Oct 2020 13:53:27 +0000 (15:53 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Oct 2020 09:13:10 +0000 (11:13 +0200)
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@redhat.com>
Reviewed-by: Matt Coleman <matt@datto.com>
src/hyperv/hyperv_driver.c
src/hyperv/hyperv_wmi.c
src/hyperv/hyperv_wmi.h

index 2ac30fa4c69fb989d79bfe72120e3adb7633d9cd..eeb65bd4d7ae3672faebb0d27c8f628c822c2279 100644 (file)
@@ -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;
     }
index 2b40e720534b505e34c59122a62df407010cb044..78d15e2a43238671918eea4780f9ab9e94874549 100644 (file)
@@ -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;
 }
 
index ee16657768bd76345190c42dfe1b24a5fbb79750..20749f2a39997894ce660f9802cf41ba004cc771 100644 (file)
@@ -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