mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-30 13:37:17 +00:00
remoteConnectOpen: Refactor cleanup
Use automatic memory freeing for 'driver' and return error right away to avoid the 'cleanup' label. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
791b4f9e0c
commit
18c09ec164
@ -1228,23 +1228,20 @@ remoteConnectOpen(virConnectPtr conn,
|
|||||||
struct private_data *priv;
|
struct private_data *priv;
|
||||||
int ret = VIR_DRV_OPEN_ERROR;
|
int ret = VIR_DRV_OPEN_ERROR;
|
||||||
unsigned int rflags = 0;
|
unsigned int rflags = 0;
|
||||||
char *driver = NULL;
|
g_autofree char *driver = NULL;
|
||||||
remoteDriverTransport transport;
|
remoteDriverTransport transport;
|
||||||
|
|
||||||
if (conn->uri) {
|
if (conn->uri) {
|
||||||
if (remoteSplitURIScheme(conn->uri, &driver, &transport) < 0)
|
if (remoteSplitURIScheme(conn->uri, &driver, &transport) < 0)
|
||||||
goto cleanup;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
} else {
|
} else {
|
||||||
/* No URI, then must be probing so use UNIX socket */
|
/* No URI, then must be probing so use UNIX socket */
|
||||||
transport = REMOTE_DRIVER_TRANSPORT_UNIX;
|
transport = REMOTE_DRIVER_TRANSPORT_UNIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (inside_daemon) {
|
if (inside_daemon) {
|
||||||
if (!conn->uri) {
|
if (!conn->uri)
|
||||||
ret = VIR_DRV_OPEN_DECLINED;
|
return VIR_DRV_OPEN_DECLINED;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If there's a driver registered we must defer to that.
|
/* If there's a driver registered we must defer to that.
|
||||||
* If there isn't a driver, we must connect in "direct"
|
* If there isn't a driver, we must connect in "direct"
|
||||||
@ -1254,15 +1251,12 @@ remoteConnectOpen(virConnectPtr conn,
|
|||||||
* host */
|
* host */
|
||||||
if (!conn->uri->server &&
|
if (!conn->uri->server &&
|
||||||
virHasDriverForURIScheme(driver) &&
|
virHasDriverForURIScheme(driver) &&
|
||||||
!virURICheckUnixSocket(conn->uri)) {
|
!virURICheckUnixSocket(conn->uri))
|
||||||
ret = VIR_DRV_OPEN_DECLINED;
|
return VIR_DRV_OPEN_DECLINED;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(priv = remoteAllocPrivateData()))
|
if (!(priv = remoteAllocPrivateData()))
|
||||||
goto cleanup;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
|
|
||||||
|
|
||||||
remoteGetURIDaemonInfo(conn->uri, transport, &rflags);
|
remoteGetURIDaemonInfo(conn->uri, transport, &rflags);
|
||||||
if (flags & VIR_CONNECT_RO)
|
if (flags & VIR_CONNECT_RO)
|
||||||
@ -1278,8 +1272,6 @@ remoteConnectOpen(virConnectPtr conn,
|
|||||||
remoteDriverUnlock(priv);
|
remoteDriverUnlock(priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(driver);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user