On 1/21/21 1:50 PM, Matt Coleman wrote:
Signed-off-by: Matt Coleman <matt(a)datto.com>
---
src/hyperv/hyperv_driver.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 8b59dd05f7..6375f6b011 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1514,10 +1514,9 @@ hypervConnectGetCapabilities(virConnectPtr conn)
static int
hypervConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
{
- int result = -1;
hypervPrivate *priv = conn->privateData;
g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
- Msvm_ProcessorSettingData *processorSettingData = NULL;
+ g_autoptr(Msvm_ProcessorSettingData) processorSettingData = NULL;
/* Get max processors definition */
virBufferAddLit(&query,
@@ -1525,21 +1524,16 @@ hypervConnectGetMaxVcpus(virConnectPtr conn, const char *type
G_GNUC_UNUSED)
"WHERE InstanceID LIKE
'Microsoft:Definition%Maximum'");
if (hypervGetWmiClass(Msvm_ProcessorSettingData, &processorSettingData) <
0)
- goto cleanup;
+ return -1;
if (!processorSettingData) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get maximum definition of
Msvm_ProcessorSettingData for host %s"),
conn->uri->server);
- goto cleanup;
+ return -1;
}
- result = processorSettingData->data->VirtualQuantity;
-
- cleanup:
- hypervFreeObject((hypervObject *)processorSettingData);
-
- return result;
+ return processorSettingData->data->VirtualQuantity;
So. Something I'm unsure of - what you're doing here is returning a
value that is stored in an object that is being auto-freed by the
cleanup when the scope of the function is exited. I *guess* that the
cleanup happens after copying the return value into the register that's
used to return it to the caller? But I'm not sure, and it could just as
easily be done in the opposite order. It's too late in the day (early in
the next day, actually) for me to compile something and look at it with
gdb to verify. Anybody else know the answer (or feel like experimenting)?
}