提交 121c09a9 编写于 作者: J John Ferlan

Replace virNetworkFree with virObjectUnref

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.
上级 8fb3aee2
......@@ -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$$)
......@@ -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;
}
......
......@@ -119,7 +119,7 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn,
VIR_WARN("Unexpected event ID %d", event->eventID);
cleanup:
virNetworkFree(net);
virObjectUnref(net);
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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"),
......
......@@ -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);
}
......
......@@ -213,7 +213,7 @@ umlBuildCommandLineNet(virConnectPtr conn,
goto error;
}
bridge = virNetworkGetBridgeName(network);
virNetworkFree(network);
virObjectUnref(network);
if (bridge == NULL)
goto error;
......
......@@ -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"),
......
......@@ -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"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册