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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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