Since virNetworkFree will call virObjectUnref anyway, let's just use that
directly so as to avoid the possibility that we inadvertently clear out
a pending error message when using the public API.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
cfg.mk | 4 ++--
daemon/remote.c | 7 +++----
src/conf/network_conf.c | 6 ++----
src/conf/network_event.c | 2 +-
src/libxl/libxl_conf.c | 7 +------
src/lxc/lxc_driver.c | 8 +-------
src/lxc/lxc_process.c | 8 +-------
src/qemu/qemu_command.c | 8 +-------
src/qemu/qemu_hotplug.c | 8 +-------
src/remote/remote_driver.c | 5 ++---
src/uml/uml_conf.c | 2 +-
src/xenconfig/xen_common.c | 2 +-
src/xenconfig/xen_sxpr.c | 2 +-
13 files changed, 18 insertions(+), 51 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index c772110..b5f853b 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -992,7 +992,7 @@ sc_prohibit_system_error_with_vir_err:
# functions. There's a corresponding exclude to allow usage within tests,
# docs, examples, tools, src/libvirt-*.c, and include/libvirt/libvirt-*.h
sc_prohibit_virXXXFree:
- @prohibit='\bvirDomainFree\b' \
+ @prohibit='\bvir(Domain|Network)Free\b' \
exclude='sc_prohibit_virXXXFree' \
halt='avoid using 'virXXXFree', use 'virObjectUnref' instead' \
$(_sc_search_regexp)
@@ -1186,4 +1186,4 @@ exclude_file_name_regexp--sc_prohibit_devname = \
^(tools/virsh.pod|cfg.mk|docs/.*)$$
exclude_file_name_regexp--sc_prohibit_virXXXFree = \
-
^(docs/|tests/|examples/|tools/|cfg.mk|src/libvirt_public.syms|include/libvirt/libvirt-domain.h|src/libvirt-(domain|qemu).c$$)
+
^(docs/|tests/|examples/|tools/|cfg.mk|src/libvirt_public.syms|include/libvirt/libvirt-(domain|network).h|src/libvirt-(domain|qemu|network).c$$)
diff --git a/daemon/remote.c b/daemon/remote.c
index 00b3e21..edae335 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4790,7 +4790,7 @@ remoteDispatchConnectListAllNetworks(virNetServerPtr server
ATTRIBUTE_UNUSED,
virNetMessageSaveError(rerr);
if (nets && nnets > 0) {
for (i = 0; i < nnets; i++)
- virNetworkFree(nets[i]);
+ virObjectUnref(nets[i]);
VIR_FREE(nets);
}
return rv;
@@ -5816,8 +5816,7 @@ remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server
ATTRIBUTE_UN
VIR_FREE(callback);
if (rv < 0)
virNetMessageSaveError(rerr);
- if (net)
- virNetworkFree(net);
+ virObjectUnref(net);
virMutexUnlock(&priv->lock);
return rv;
}
@@ -6202,7 +6201,7 @@ remoteDispatchNetworkGetDHCPLeases(virNetServerPtr server
ATTRIBUTE_UNUSED,
virNetworkDHCPLeaseFree(leases[i]);
VIR_FREE(leases);
}
- virNetworkFree(net);
+ virObjectUnref(net);
return rv;
}
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 067334e..a249e32 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -4463,10 +4463,8 @@ virNetworkObjListExport(virConnectPtr conn,
cleanup:
if (tmp_nets) {
- for (i = 0; i < nnets; i++) {
- if (tmp_nets[i])
- virNetworkFree(tmp_nets[i]);
- }
+ for (i = 0; i < nnets; i++)
+ virObjectUnref(tmp_nets[i]);
}
VIR_FREE(tmp_nets);
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index 991591a..8623940 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -119,7 +119,7 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn,
VIR_WARN("Unexpected event ID %d", event->eventID);
cleanup:
- virNetworkFree(net);
+ virObjectUnref(net);
}
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index e296ffc..0555b91 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1058,7 +1058,6 @@ libxlMakeNic(virDomainDefPtr def,
char *brname = NULL;
virNetworkPtr network;
virConnectPtr conn;
- virErrorPtr errobj;
if (!(conn = virConnectOpen("xen:///system")))
return -1;
@@ -1078,11 +1077,7 @@ libxlMakeNic(virDomainDefPtr def,
VIR_FREE(brname);
- /* Preserve any previous failure */
- errobj = virSaveLastError();
- virNetworkFree(network);
- virSetError(errobj);
- virFreeError(errobj);
+ virObjectUnref(network);
virObjectUnref(conn);
if (fail)
return -1;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 93db1ee..97caee3 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4178,19 +4178,13 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
virNetworkPtr network;
char *brname = NULL;
bool fail = false;
- virErrorPtr errobj;
if (!(network = virNetworkLookupByName(conn, net->data.network.name)))
goto cleanup;
if (!(brname = virNetworkGetBridgeName(network)))
fail = true;
- /* Make sure any above failure is preserved */
- errobj = virSaveLastError();
- virNetworkFree(network);
- virSetError(errobj);
- virFreeError(errobj);
-
+ virObjectUnref(network);
if (fail)
goto cleanup;
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 9208f02..de574a9 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -386,7 +386,6 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
virNetworkPtr network;
char *brname = NULL;
bool fail = false;
- virErrorPtr errobj;
if (!(network = virNetworkLookupByName(conn,
net->data.network.name)))
@@ -394,12 +393,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
if (!(brname = virNetworkGetBridgeName(network)))
fail = true;
- /* Make sure any above failure is preserved */
- errobj = virSaveLastError();
- virNetworkFree(network);
- virSetError(errobj);
- virFreeError(errobj);
-
+ virObjectUnref(network);
if (fail)
goto cleanup;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4ed6506..1831323 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -298,7 +298,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
bool fail = false;
- virErrorPtr errobj;
virNetworkPtr network = virNetworkLookupByName(conn,
net->data.network.name);
if (!network)
@@ -307,12 +306,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
if (!(brname = virNetworkGetBridgeName(network)))
fail = true;
- /* Make sure any above failure is preserved */
- errobj = virSaveLastError();
- virNetworkFree(network);
- virSetError(errobj);
- virFreeError(errobj);
-
+ virObjectUnref(network);
if (fail)
return ret;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f2740f4..1971b0a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1763,7 +1763,6 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr
net)
if (VIR_STRDUP(brname, tmpbr) < 0)
goto cleanup;
} else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
- virErrorPtr errobj;
virNetworkPtr network;
if (!(network = virNetworkLookupByName(conn, net->data.network.name))) {
@@ -1774,12 +1773,7 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr
net)
}
brname = virNetworkGetBridgeName(network);
- /* Make sure any above failure is preserved */
- errobj = virSaveLastError();
- virNetworkFree(network);
- virSetError(errobj);
- virFreeError(errobj);
-
+ virObjectUnref(network);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Interface type %d has no bridge name"),
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 48e2e25..c23a087 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3063,8 +3063,7 @@ remoteConnectListAllNetworks(virConnectPtr conn,
cleanup:
if (tmp_nets) {
for (i = 0; i < ret.nets.nets_len; i++)
- if (tmp_nets[i])
- virNetworkFree(tmp_nets[i]);
+ virObjectUnref(tmp_nets[i]);
VIR_FREE(tmp_nets);
}
@@ -5529,7 +5528,7 @@ remoteNetworkBuildEventLifecycle(virNetClientProgramPtr prog
ATTRIBUTE_UNUSED,
event = virNetworkEventLifecycleNew(net->name, net->uuid, msg->event,
msg->detail);
- virNetworkFree(net);
+ virObjectUnref(net);
remoteEventQueue(priv, event, msg->callbackID);
}
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 9dcd4ae..7a5d62b 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -213,7 +213,7 @@ umlBuildCommandLineNet(virConnectPtr conn,
goto error;
}
bridge = virNetworkGetBridgeName(network);
- virNetworkFree(network);
+ virObjectUnref(network);
if (bridge == NULL)
goto error;
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 29c6c34..7f4ec89 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1245,7 +1245,7 @@ xenFormatNet(virConnectPtr conn,
return -1;
}
bridge = virNetworkGetBridgeName(network);
- virNetworkFree(network);
+ virObjectUnref(network);
if (!bridge) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network %s is not active"),
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index a667814..d8783e9 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1915,7 +1915,7 @@ xenFormatSxprNet(virConnectPtr conn,
}
bridge = virNetworkGetBridgeName(network);
- virNetworkFree(network);
+ virObjectUnref(network);
if (!bridge) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("network %s is not active"),
--
1.9.3