hyperv: Make it obvious that hypervInvokeMethod() consumes an argument

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>
This commit is contained in:
Michal Privoznik 2020-10-15 15:53:27 +02:00
parent 2508d10f67
commit f978e2e6ef
3 changed files with 20 additions and 11 deletions

View File

@ -1677,7 +1677,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
goto cleanup; goto cleanup;
} }
if (hypervInvokeMethod(priv, params, NULL) < 0) { if (hypervInvokeMethod(priv, &params, NULL) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key %d"), virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key %d"),
translatedKeycodes[i]); translatedKeycodes[i]);
goto cleanup; goto cleanup;
@ -1704,7 +1704,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
goto cleanup; goto cleanup;
} }
if (hypervInvokeMethod(priv, params, NULL) < 0) { if (hypervInvokeMethod(priv, &params, NULL) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not release key %s"), virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not release key %s"),
keycodeStr); keycodeStr);
goto cleanup; 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")); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not set memory"));
goto cleanup; goto cleanup;
} }

View File

@ -753,17 +753,24 @@ hypervSerializeEmbeddedParam(hypervParamPtr p, const char *resourceUri,
/* /*
* hypervInvokeMethod: * hypervInvokeMethod:
* @priv: hypervPrivate object associated with the connection * @priv: hypervPrivate object associated with the connection
* @params: object containing the all necessary information for method * @paramsPtr: pointer to object containing the all necessary information for
* invocation * method invocation (consumed on invocation)
* @res: Optional out parameter to contain the response XML. * @res: Optional out parameter to contain the response XML.
* *
* Performs an invocation described by @params, and optionally returns the * Performs an invocation described by object at @paramsPtr, and optionally
* XML containing the result. Returns -1 on failure, 0 on success. * 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 int
hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params, hypervInvokeMethod(hypervPrivate *priv,
WsXmlDocH *res) hypervInvokeParamsListPtr *paramsPtr,
WsXmlDocH *res)
{ {
hypervInvokeParamsListPtr params = *paramsPtr;
int result = -1; int result = -1;
size_t i = 0; size_t i = 0;
int returnCode; int returnCode;
@ -939,6 +946,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params,
VIR_FREE(instanceID); VIR_FREE(instanceID);
hypervFreeObject(priv, (hypervObject *)job); hypervFreeObject(priv, (hypervObject *)job);
hypervFreeInvokeParams(params); hypervFreeInvokeParams(params);
*paramsPtr = NULL;
return result; return result;
} }

View File

@ -154,8 +154,9 @@ int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate *priv
void hypervFreeEmbeddedParam(virHashTablePtr p); void hypervFreeEmbeddedParam(virHashTablePtr p);
int hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params, int hypervInvokeMethod(hypervPrivate *priv,
WsXmlDocH *res); hypervInvokeParamsListPtr *paramsPtr,
WsXmlDocH *res);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* CIM/Msvm_ReturnCode * CIM/Msvm_ReturnCode