1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

use g_autoptr for all virConnectPtrs used with virGetConnectNetwork()

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Laine Stump 2021-01-08 00:31:05 -05:00
parent c2b2cdf746
commit 7f37110f2f
5 changed files with 17 additions and 35 deletions

View File

@ -31040,7 +31040,7 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virNetworkPortPtr port = NULL; virNetworkPortPtr port = NULL;
virTypedParameterPtr params = NULL; virTypedParameterPtr params = NULL;
int nparams = 0; int nparams = 0;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
int ret = -1; int ret = -1;
if (!(conn = virGetConnectNetwork())) if (!(conn = virGetConnectNetwork()))
@ -31060,7 +31060,6 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(conn);
virTypedParamsFree(params, nparams); virTypedParamsFree(params, nparams);
virObjectUnref(port); virObjectUnref(port);
virObjectUnref(net); virObjectUnref(net);

View File

@ -25,6 +25,7 @@
#include "libxl_domain.h" #include "libxl_domain.h"
#include "libxl_capabilities.h" #include "libxl_capabilities.h"
#include "datatypes.h"
#include "viralloc.h" #include "viralloc.h"
#include "virfile.h" #include "virfile.h"
#include "virerror.h" #include "virerror.h"
@ -849,7 +850,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
char *file; char *file;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI; unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
#ifdef LIBXL_HAVE_PVUSB #ifdef LIBXL_HAVE_PVUSB
hostdev_flags |= VIR_HOSTDEV_SP_USB; hostdev_flags |= VIR_HOSTDEV_SP_USB;
@ -936,7 +937,6 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
} }
virDomainObjRemoveTransientDef(vm); virDomainObjRemoveTransientDef(vm);
virObjectUnref(conn);
} }
/* /*
@ -1050,7 +1050,7 @@ static int
libxlNetworkPrepareDevices(virDomainDefPtr def) libxlNetworkPrepareDevices(virDomainDefPtr def)
{ {
size_t i; size_t i;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
int ret = -1; int ret = -1;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
@ -1096,7 +1096,6 @@ libxlNetworkPrepareDevices(virDomainDefPtr def)
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(conn);
return ret; return ret;
} }

View File

@ -355,7 +355,7 @@ static void
libxlReconnectNotifyNets(virDomainDefPtr def) libxlReconnectNotifyNets(virDomainDefPtr def)
{ {
size_t i; size_t i;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i]; virDomainNetDefPtr net = def->nets[i];
@ -372,8 +372,6 @@ libxlReconnectNotifyNets(virDomainDefPtr def)
virDomainNetNotifyActualDevice(conn, def, net); virDomainNetNotifyActualDevice(conn, def, net);
} }
virObjectUnref(conn);
} }
@ -3403,7 +3401,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
libxl_device_nic nic; libxl_device_nic nic;
int ret = -1; int ret = -1;
char mac[VIR_MAC_STRING_BUFLEN]; char mac[VIR_MAC_STRING_BUFLEN];
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
virErrorPtr save_err = NULL; virErrorPtr save_err = NULL;
libxl_device_nic_init(&nic); libxl_device_nic_init(&nic);
@ -3478,7 +3476,6 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && conn) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && conn)
virDomainNetReleaseActualDevice(conn, vm->def, net); virDomainNetReleaseActualDevice(conn, vm->def, net);
} }
virObjectUnref(conn);
virObjectUnref(cfg); virObjectUnref(cfg);
virErrorRestore(&save_err); virErrorRestore(&save_err);
return ret; return ret;
@ -3904,14 +3901,12 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
libxl_device_nic_dispose(&nic); libxl_device_nic_dispose(&nic);
if (!ret) { if (!ret) {
if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) { if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virConnectPtr conn = virGetConnectNetwork(); g_autoptr(virConnect) conn = virGetConnectNetwork();
if (conn) { if (conn)
virDomainNetReleaseActualDevice(conn, vm->def, detach); virDomainNetReleaseActualDevice(conn, vm->def, detach);
virObjectUnref(conn); else
} else {
VIR_WARN("Unable to release network device '%s'", NULLSTR(detach->ifname)); VIR_WARN("Unable to release network device '%s'", NULLSTR(detach->ifname));
} }
}
virDomainNetRemove(vm->def, detachidx); virDomainNetRemove(vm->def, detachidx);
} }
virObjectUnref(cfg); virObjectUnref(cfg);

View File

@ -3463,14 +3463,9 @@ lxcDomainAttachDeviceNetLive(virLXCDriverPtr driver,
* to the one defined in the network definition. * to the one defined in the network definition.
*/ */
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) { if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virConnectPtr netconn = virGetConnectNetwork(); g_autoptr(virConnect) netconn = virGetConnectNetwork();
if (!netconn) if (!netconn || virDomainNetAllocateActualDevice(netconn, vm->def, net) < 0)
return -1; return -1;
if (virDomainNetAllocateActualDevice(netconn, vm->def, net) < 0) {
virObjectUnref(netconn);
return -1;
}
virObjectUnref(netconn);
} }
/* final validation now that actual type is known */ /* final validation now that actual type is known */
@ -4028,14 +4023,12 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
if (!ret) { if (!ret) {
virErrorPreserveLast(&save_err); virErrorPreserveLast(&save_err);
if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) { if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virConnectPtr conn = virGetConnectNetwork(); g_autoptr(virConnect) conn = virGetConnectNetwork();
if (conn) { if (conn)
virDomainNetReleaseActualDevice(conn, vm->def, detach); virDomainNetReleaseActualDevice(conn, vm->def, detach);
virObjectUnref(conn); else
} else {
VIR_WARN("Unable to release network device '%s'", NULLSTR(detach->ifname)); VIR_WARN("Unable to release network device '%s'", NULLSTR(detach->ifname));
} }
}
virDomainNetRemove(vm->def, detachidx); virDomainNetRemove(vm->def, detachidx);
virDomainNetDefFree(detach); virDomainNetDefFree(detach);
virErrorRestore(&save_err); virErrorRestore(&save_err);

View File

@ -172,7 +172,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virLXCDomainObjPrivatePtr priv = vm->privateData; virLXCDomainObjPrivatePtr priv = vm->privateData;
const virNetDevVPortProfile *vport = NULL; const virNetDevVPortProfile *vport = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
VIR_DEBUG("Cleanup VM name=%s pid=%d reason=%d flags=0x%x", VIR_DEBUG("Cleanup VM name=%s pid=%d reason=%d flags=0x%x",
vm->def->name, (int)vm->pid, (int)reason, flags); vm->def->name, (int)vm->pid, (int)reason, flags);
@ -281,7 +281,6 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virDomainObjRemoveTransientDef(vm); virDomainObjRemoveTransientDef(vm);
virObjectUnref(cfg); virObjectUnref(cfg);
virObjectUnref(conn);
} }
@ -571,7 +570,7 @@ virLXCProcessSetupInterfaces(virLXCDriverPtr driver,
size_t niface = 0; size_t niface = 0;
virDomainNetDefPtr net; virDomainNetDefPtr net;
virDomainNetType type; virDomainNetType type;
virConnectPtr netconn = NULL; g_autoptr(virConnect) netconn = NULL;
virErrorPtr save_err = NULL; virErrorPtr save_err = NULL;
*veths = g_new0(char *, def->nnets + 1); *veths = g_new0(char *, def->nnets + 1);
@ -680,7 +679,6 @@ virLXCProcessSetupInterfaces(virLXCDriverPtr driver,
} }
virErrorRestore(&save_err); virErrorRestore(&save_err);
} }
virObjectUnref(netconn);
return ret; return ret;
} }
@ -1634,7 +1632,7 @@ static void
virLXCProcessReconnectNotifyNets(virDomainDefPtr def) virLXCProcessReconnectNotifyNets(virDomainDefPtr def)
{ {
size_t i; size_t i;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i]; virDomainNetDefPtr net = def->nets[i];
@ -1668,8 +1666,6 @@ virLXCProcessReconnectNotifyNets(virDomainDefPtr def)
virDomainNetNotifyActualDevice(conn, def, net); virDomainNetNotifyActualDevice(conn, def, net);
} }
virObjectUnref(conn);
} }