hyperv: use g_autoptr for WMI classes in hypervNodeGetInfo

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Matt Coleman 2021-01-21 13:50:51 -05:00 committed by Laine Stump
parent 770186542f
commit e6d09928b6

View File

@ -1540,20 +1540,19 @@ hypervConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
static int static int
hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
{ {
int result = -1;
hypervPrivate *priv = conn->privateData; hypervPrivate *priv = conn->privateData;
Win32_ComputerSystem *computerSystem = NULL; g_autoptr(Win32_ComputerSystem) computerSystem = NULL;
Win32_Processor *processorList = NULL; g_autoptr(Win32_Processor) processorList = NULL;
Win32_Processor *processor = NULL; Win32_Processor *processor = NULL;
char *tmp; char *tmp;
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
if (hypervGetPhysicalSystemList(priv, &computerSystem) < 0) if (hypervGetPhysicalSystemList(priv, &computerSystem) < 0)
goto cleanup; return -1;
if (hypervGetProcessorsByName(priv, computerSystem->data->Name, &processorList) < 0) { if (hypervGetProcessorsByName(priv, computerSystem->data->Name, &processorList) < 0) {
goto cleanup; return -1;
} }
/* Strip the string to fit more relevant information in 32 chars */ /* Strip the string to fit more relevant information in 32 chars */
@ -1583,7 +1582,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("CPU model %s too long for destination"), _("CPU model %s too long for destination"),
processorList->data->Name); processorList->data->Name);
goto cleanup; return -1;
} }
info->memory = computerSystem->data->TotalPhysicalMemory / 1024; /* byte to kilobyte */ info->memory = computerSystem->data->TotalPhysicalMemory / 1024; /* byte to kilobyte */
@ -1600,13 +1599,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
info->threads = processorList->data->NumberOfLogicalProcessors / info->cores; info->threads = processorList->data->NumberOfLogicalProcessors / info->cores;
info->cpus = info->sockets * info->cores; info->cpus = info->sockets * info->cores;
result = 0; return 0;
cleanup:
hypervFreeObject((hypervObject *)computerSystem);
hypervFreeObject((hypervObject *)processorList);
return result;
} }