As pointed out by Ján Tomko, "no_memory seems suspicious in the times of
abort()".
As libvirt decided to take the path to not report OOM and simply abort
when it happens, let's get rid of the no_memory labels and simplify the
code around them.
Signed-off-by: Fabiano Fidêncio <fidencio(a)redhat.com>
---
src/rpc/virnetclient.c | 42 ++++++++++++------------------------------
1 file changed, 12 insertions(+), 30 deletions(-)
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index eba8b865d1..50489b754c 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -439,7 +439,6 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
virURIPtr uri)
{
virNetSocketPtr sock = NULL;
- virNetClientPtr ret = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_autofree char *nc = NULL;
@@ -457,7 +456,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
confdir = virGetUserConfigDirectory();
virBufferAsprintf(&buf, "%s/known_hosts", confdir);
if (!(knownhosts = virBufferContentAndReset(&buf)))
- goto no_memory;
+ return NULL;
}
if (privkeyPath) {
@@ -465,7 +464,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
} else {
homedir = virGetUserDirectory();
if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0)
- goto no_memory;
+ return NULL;
}
if (!authMethods) {
@@ -483,11 +482,11 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
virBufferEscapeShell(&buf, netcatPath);
if (!(nc = virBufferContentAndReset(&buf)))
- goto no_memory;
+ return NULL;
virBufferEscapeShell(&buf, nc);
VIR_FREE(nc);
if (!(nc = virBufferContentAndReset(&buf)))
- goto no_memory;
+ return NULL;
virBufferAsprintf(&buf,
"sh -c "
@@ -500,24 +499,16 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
nc, nc, socketPath);
if (!(command = virBufferContentAndReset(&buf)))
- goto no_memory;
+ return NULL;
if (virNetSocketNewConnectLibSSH2(host, port,
family,
username, privkey,
knownhosts, knownHostsVerify, authMethods,
command, authPtr, uri, &sock) != 0)
- goto cleanup;
-
- if (!(ret = virNetClientNew(sock, NULL)))
- goto cleanup;
-
- cleanup:
- return ret;
+ return NULL;
- no_memory:
- virReportOOMError();
- goto cleanup;
+ return virNetClientNew(sock, NULL);
}
#undef DEFAULT_VALUE
@@ -538,7 +529,6 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
virURIPtr uri)
{
virNetSocketPtr sock = NULL;
- virNetClientPtr ret = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_autofree char *nc = NULL;
@@ -562,7 +552,7 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
} else {
homedir = virGetUserDirectory();
if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0)
- goto no_memory;
+ return NULL;
}
if (!authMethods) {
@@ -580,11 +570,11 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
virBufferEscapeShell(&buf, netcatPath);
if (!(nc = virBufferContentAndReset(&buf)))
- goto no_memory;
+ return NULL;
virBufferEscapeShell(&buf, nc);
VIR_FREE(nc);
if (!(nc = virBufferContentAndReset(&buf)))
- goto no_memory;
+ return NULL;
command = g_strdup_printf("sh -c "
"'if '%s' -q 2>&1 | grep
\"requires an argument\" >/dev/null 2>&1; then "
@@ -596,17 +586,9 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
username, privkey,
knownhosts, knownHostsVerify, authMethods,
command, authPtr, uri, &sock) != 0)
- goto cleanup;
-
- if (!(ret = virNetClientNew(sock, NULL)))
- goto cleanup;
-
- cleanup:
- return ret;
+ return NULL;
- no_memory:
- virReportOOMError();
- goto cleanup;
+ return virNetClientNew(sock, NULL);
}
#undef DEFAULT_VALUE
--
2.24.1