1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

Use g_auto for stealing virCaps

Convert all the functions that generate virCaps to use g_auto
and g_steal_pointer.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2021-12-10 15:07:13 +01:00
parent 4eaa499c8b
commit eb52b9f8af
9 changed files with 18 additions and 27 deletions

View File

@ -52,7 +52,7 @@ VIR_ONCE_GLOBAL_INIT(virCHConfig);
/* Functions */
virCaps *virCHDriverCapsInit(void)
{
virCaps *caps;
g_autoptr(virCaps) caps = NULL;
virCapsGuest *guest;
if ((caps = virCapabilitiesNew(virArchFromHost(),
@ -70,10 +70,9 @@ virCaps *virCHDriverCapsInit(void)
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM,
NULL, NULL, 0, NULL);
return caps;
return g_steal_pointer(&caps);
cleanup:
virObjectUnref(caps);
return NULL;
}

View File

@ -262,7 +262,7 @@ hypervLookupHostSystemBiosUuid(hypervPrivate *priv, unsigned char *uuid)
static virCaps *
hypervCapsInit(hypervPrivate *priv)
{
virCaps *caps = NULL;
g_autoptr(virCaps) caps = NULL;
virCapsGuest *guest = NULL;
caps = virCapabilitiesNew(VIR_ARCH_X86_64, 1, 1);
@ -287,10 +287,9 @@ hypervCapsInit(hypervPrivate *priv)
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV,
NULL, NULL, 0, NULL);
return caps;
return g_steal_pointer(&caps);
error:
virObjectUnref(caps);
return NULL;
}

View File

@ -635,7 +635,7 @@ libxlMakeDomainDeviceHostdevCaps(virDomainCapsDeviceHostdev *dev)
virCaps *
libxlMakeCapabilities(libxl_ctx *ctx)
{
virCaps *caps;
g_autoptr(virCaps) caps = NULL;
#ifdef LIBXL_HAVE_NO_SUSPEND_RESUME
if ((caps = virCapabilitiesNew(virArchFromHost(), false, false)) == NULL)
@ -653,10 +653,9 @@ libxlMakeCapabilities(libxl_ctx *ctx)
if (libxlCapsInitGuests(ctx, caps) < 0)
goto error;
return caps;
return g_steal_pointer(&caps);
error:
virObjectUnref(caps);
return NULL;
}

View File

@ -58,7 +58,7 @@ VIR_ONCE_GLOBAL_INIT(virLXCConfig);
/* Functions */
virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
{
virCaps *caps;
g_autoptr(virCaps) caps = NULL;
virCapsGuest *guest;
virArch altArch;
g_autofree char *lxc_path = NULL;
@ -138,10 +138,9 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver)
VIR_INFO("No driver, not initializing security driver");
}
return caps;
return g_steal_pointer(&caps);
error:
virObjectUnref(caps);
return NULL;
}

View File

@ -291,7 +291,7 @@ static virCaps *
testBuildCapabilities(virConnectPtr conn)
{
testDriver *privconn = conn->privateData;
virCaps *caps;
g_autoptr(virCaps) caps = NULL;
virCapsGuest *guest;
int guest_types[] = { VIR_DOMAIN_OSTYPE_HVM,
VIR_DOMAIN_OSTYPE_XEN };
@ -361,10 +361,9 @@ testBuildCapabilities(virConnectPtr conn)
caps->host.secModels[0].doi = g_strdup("");
return caps;
return g_steal_pointer(&caps);
error:
virObjectUnref(caps);
return NULL;
}

View File

@ -64,7 +64,7 @@ vmwareFreeDriver(struct vmware_driver *driver)
virCaps *
vmwareCapsInit(void)
{
virCaps *caps = NULL;
g_autoptr(virCaps) caps = NULL;
virCapsGuest *guest = NULL;
if ((caps = virCapabilitiesNew(virArchFromHost(),
@ -106,11 +106,10 @@ vmwareCapsInit(void)
guest = NULL;
}
return caps;
return g_steal_pointer(&caps);
error:
virCapabilitiesFreeGuest(guest);
virObjectUnref(caps);
return NULL;
}

View File

@ -94,7 +94,7 @@ vzCapsAddGuestDomain(virCaps *caps,
static virCaps *
vzBuildCapabilities(void)
{
virCaps *caps = NULL;
g_autoptr(virCaps) caps = NULL;
virNodeInfo nodeinfo;
virDomainOSType ostypes[] = {
VIR_DOMAIN_OSTYPE_HVM,
@ -137,10 +137,9 @@ vzBuildCapabilities(void)
if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
goto error;
return caps;
return g_steal_pointer(&caps);
error:
virObjectUnref(caps);
return NULL;
}

View File

@ -86,7 +86,7 @@ static virCaps *
testGetCaps(char *capsData, const testQemuData *data)
{
g_autoptr(virQEMUCaps) qemuCaps = NULL;
virCaps *caps = NULL;
g_autoptr(virCaps) caps = NULL;
virArch arch = virArchFromString(data->archName);
g_autofree char *binary = NULL;
@ -110,10 +110,9 @@ testGetCaps(char *capsData, const testQemuData *data)
goto error;
}
return caps;
return g_steal_pointer(&caps);
error:
virObjectUnref(caps);
return NULL;
}

View File

@ -11,7 +11,7 @@
static virCaps *
testXLInitCaps(void)
{
virCaps *caps;
g_autoptr(virCaps) caps = NULL;
virCapsGuest *guest;
virCapsGuestMachine **machines;
int nmachines;
@ -68,11 +68,10 @@ testXLInitCaps(void)
virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN,
NULL, NULL, 0, NULL);
return caps;
return g_steal_pointer(&caps);
cleanup:
virCapabilitiesFreeMachines(machines, nmachines);
virObjectUnref(caps);
return NULL;
}