mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
network: replace explicit virNetworkDefFree() with g_autoptr(virNetworkDef)
Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
635be49d81
commit
bea8da6b12
@ -3051,7 +3051,7 @@ networkCreateXMLFlags(virConnectPtr conn,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virNetworkDriverState *driver = networkGetDriver();
|
virNetworkDriverState *driver = networkGetDriver();
|
||||||
virNetworkDef *newDef;
|
g_autoptr(virNetworkDef) newDef = NULL;
|
||||||
virNetworkObj *obj = NULL;
|
virNetworkObj *obj = NULL;
|
||||||
virNetworkDef *def;
|
virNetworkDef *def;
|
||||||
virNetworkPtr net = NULL;
|
virNetworkPtr net = NULL;
|
||||||
@ -3077,6 +3077,7 @@ networkCreateXMLFlags(virConnectPtr conn,
|
|||||||
VIR_NETWORK_OBJ_LIST_ADD_LIVE |
|
VIR_NETWORK_OBJ_LIST_ADD_LIVE |
|
||||||
VIR_NETWORK_OBJ_LIST_ADD_CHECK_LIVE)))
|
VIR_NETWORK_OBJ_LIST_ADD_CHECK_LIVE)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
newDef = NULL;
|
newDef = NULL;
|
||||||
def = virNetworkObjGetDef(obj);
|
def = virNetworkObjGetDef(obj);
|
||||||
|
|
||||||
@ -3094,7 +3095,6 @@ networkCreateXMLFlags(virConnectPtr conn,
|
|||||||
net = virGetNetwork(conn, def->name, def->uuid);
|
net = virGetNetwork(conn, def->name, def->uuid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetworkDefFree(newDef);
|
|
||||||
virObjectEventStateQueue(driver->networkEventState, event);
|
virObjectEventStateQueue(driver->networkEventState, event);
|
||||||
virNetworkObjEndAPI(&obj);
|
virNetworkObjEndAPI(&obj);
|
||||||
return net;
|
return net;
|
||||||
@ -3115,8 +3115,8 @@ networkDefineXMLFlags(virConnectPtr conn,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virNetworkDriverState *driver = networkGetDriver();
|
virNetworkDriverState *driver = networkGetDriver();
|
||||||
virNetworkDef *def = NULL;
|
g_autoptr(virNetworkDef) def = NULL;
|
||||||
bool freeDef = true;
|
virNetworkDef *defAlias;
|
||||||
virNetworkObj *obj = NULL;
|
virNetworkObj *obj = NULL;
|
||||||
virNetworkPtr net = NULL;
|
virNetworkPtr net = NULL;
|
||||||
virObjectEvent *event = NULL;
|
virObjectEvent *event = NULL;
|
||||||
@ -3127,6 +3127,8 @@ networkDefineXMLFlags(virConnectPtr conn,
|
|||||||
!!(flags & VIR_NETWORK_DEFINE_VALIDATE))))
|
!!(flags & VIR_NETWORK_DEFINE_VALIDATE))))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
defAlias = def; /* so we can still ref the object after nullifying def */
|
||||||
|
|
||||||
if (virNetworkDefineXMLFlagsEnsureACL(conn, def) < 0)
|
if (virNetworkDefineXMLFlagsEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -3136,11 +3138,11 @@ networkDefineXMLFlags(virConnectPtr conn,
|
|||||||
if (!(obj = virNetworkObjAssignDef(driver->networks, def, 0)))
|
if (!(obj = virNetworkObjAssignDef(driver->networks, def, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* def was assigned to network object */
|
/* def was assigned to network object so don't autofree */
|
||||||
freeDef = false;
|
def = NULL;
|
||||||
|
|
||||||
if (virNetworkSaveConfig(driver->networkConfigDir,
|
if (virNetworkSaveConfig(driver->networkConfigDir,
|
||||||
def, network_driver->xmlopt) < 0) {
|
defAlias, network_driver->xmlopt) < 0) {
|
||||||
if (!virNetworkObjIsActive(obj)) {
|
if (!virNetworkObjIsActive(obj)) {
|
||||||
virNetworkObjRemoveInactive(driver->networks, obj);
|
virNetworkObjRemoveInactive(driver->networks, obj);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -3153,17 +3155,15 @@ networkDefineXMLFlags(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
event = virNetworkEventLifecycleNew(def->name, def->uuid,
|
event = virNetworkEventLifecycleNew(defAlias->name, defAlias->uuid,
|
||||||
VIR_NETWORK_EVENT_DEFINED,
|
VIR_NETWORK_EVENT_DEFINED,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
VIR_INFO("Defining network '%s'", def->name);
|
VIR_INFO("Defining network '%s'", defAlias->name);
|
||||||
net = virGetNetwork(conn, def->name, def->uuid);
|
net = virGetNetwork(conn, defAlias->name, defAlias->uuid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectEventStateQueue(driver->networkEventState, event);
|
virObjectEventStateQueue(driver->networkEventState, event);
|
||||||
if (freeDef)
|
|
||||||
virNetworkDefFree(def);
|
|
||||||
virNetworkObjEndAPI(&obj);
|
virNetworkObjEndAPI(&obj);
|
||||||
return net;
|
return net;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user