Re: [PATCH 30/55] hyperv: use g_autoptr for WMI classes in hypervDomainGetVcpusFlags

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

 



On 1/21/21 1:51 PM, Matt Coleman wrote:
Signed-off-by: Matt Coleman <matt@xxxxxxxxx>
---
  src/hyperv/hyperv_driver.c | 30 ++++++++++--------------------
  1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index f056761338..0642e42b35 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -2023,12 +2023,11 @@ hypervDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
  static int
  hypervDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
  {
-    int result = -1;
      char uuid_string[VIR_UUID_STRING_BUFLEN];
      hypervPrivate *priv = domain->conn->privateData;
-    Msvm_ComputerSystem *computerSystem = NULL;
-    Msvm_ProcessorSettingData *proc_sd = NULL;
-    Msvm_VirtualSystemSettingData *vssd = NULL;
+    g_autoptr(Msvm_ComputerSystem) computerSystem = NULL;
+    g_autoptr(Msvm_ProcessorSettingData) proc_sd = NULL;
+    g_autoptr(Msvm_VirtualSystemSettingData) vssd = NULL;
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
                    VIR_DOMAIN_VCPU_CONFIG |
@@ -2038,36 +2037,27 @@ hypervDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
/* Start by getting the Msvm_ComputerSystem */
      if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
-        goto cleanup;
+        return -1;
/* Check @flags to see if we are to query a running domain, and fail
       * if that domain is not running */
      if (flags & VIR_DOMAIN_VCPU_LIVE &&
          computerSystem->data->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_ENABLED) {
          virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not active"));
-        goto cleanup;
+        return -1;
      }
/* Check @flags to see if we are to return the maximum vCPU limit */
-    if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
-        result = hypervConnectGetMaxVcpus(domain->conn, NULL);
-        goto cleanup;
-    }
+    if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
+        return hypervConnectGetMaxVcpus(domain->conn, NULL);
if (hypervGetMsvmVirtualSystemSettingDataFromUUID(priv, uuid_string, &vssd) < 0)
-        goto cleanup;
+        return -1;
if (hypervGetProcessorSD(priv, vssd->data->InstanceID, &proc_sd) < 0)
-        goto cleanup;
-
-    result = proc_sd->data->VirtualQuantity;
-
- cleanup:
-    hypervFreeObject((hypervObject *)computerSystem);
-    hypervFreeObject((hypervObject *)vssd);
-    hypervFreeObject((hypervObject *)proc_sd);
+        return -1;
- return result;
+    return proc_sd->data->VirtualQuantity;


Again, returning a value that is coming out of an auto-freed object. (Each time I see it, I'm more convinced that it probably does the right thing...)





[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