From: Peter Krempa Date: Thu, 8 Sep 2022 16:00:12 +0000 (+0200) Subject: remoteConnectOpen: Refactor cleanup X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=18c09ec164a4b2fd3f213c764a2a19ef5b403d1f;p=libvirt.git remoteConnectOpen: Refactor cleanup Use automatic memory freeing for 'driver' and return error right away to avoid the 'cleanup' label. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 0ca365c4cc..b670284211 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1228,23 +1228,20 @@ remoteConnectOpen(virConnectPtr conn, struct private_data *priv; int ret = VIR_DRV_OPEN_ERROR; unsigned int rflags = 0; - char *driver = NULL; + g_autofree char *driver = NULL; remoteDriverTransport transport; if (conn->uri) { if (remoteSplitURIScheme(conn->uri, &driver, &transport) < 0) - goto cleanup; + return VIR_DRV_OPEN_ERROR; } else { /* No URI, then must be probing so use UNIX socket */ transport = REMOTE_DRIVER_TRANSPORT_UNIX; } - if (inside_daemon) { - if (!conn->uri) { - ret = VIR_DRV_OPEN_DECLINED; - goto cleanup; - } + if (!conn->uri) + return VIR_DRV_OPEN_DECLINED; /* If there's a driver registered we must defer to that. * If there isn't a driver, we must connect in "direct" @@ -1254,15 +1251,12 @@ remoteConnectOpen(virConnectPtr conn, * host */ if (!conn->uri->server && virHasDriverForURIScheme(driver) && - !virURICheckUnixSocket(conn->uri)) { - ret = VIR_DRV_OPEN_DECLINED; - goto cleanup; - } + !virURICheckUnixSocket(conn->uri)) + return VIR_DRV_OPEN_DECLINED; } if (!(priv = remoteAllocPrivateData())) - goto cleanup; - + return VIR_DRV_OPEN_ERROR; remoteGetURIDaemonInfo(conn->uri, transport, &rflags); if (flags & VIR_CONNECT_RO) @@ -1278,8 +1272,6 @@ remoteConnectOpen(virConnectPtr conn, remoteDriverUnlock(priv); } - cleanup: - VIR_FREE(driver); return ret; }