提交 d051e7f7 编写于 作者: N Nikolay Shirokovskiy

rpc: virNetClientNew: fix socket leak on error path

if virNetClientNew finishes with error before sock is set
to client object then sock does not get unrefed. This is
unexpected by function clients like virNetClientNewUNIX.
Let's make sure sock gets unrefed on any error path.

Next some clients like virNetClientNewLibSSH2 try to unref
sock on virNetClientNew errors. This is not correct even
before this patch because in some cases virNetClientNew
unrefed sock on error path by itself. Let's give up
sock managment to virNetClientNew entirely.
Signed-off-by: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 b70fb35d
......@@ -299,7 +299,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
int wakeupFD[2] = { -1, -1 };
if (virNetClientInitialize() < 0)
return NULL;
goto error;
if (pipe2(wakeupFD, O_CLOEXEC) < 0) {
virReportSystemError(errno, "%s",
......@@ -311,6 +311,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
goto error;
client->sock = sock;
sock = NULL;
client->wakeupReadFD = wakeupFD[0];
client->wakeupSendFD = wakeupFD[1];
wakeupFD[0] = wakeupFD[1] = -1;
......@@ -327,6 +328,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
VIR_FORCE_CLOSE(wakeupFD[0]);
VIR_FORCE_CLOSE(wakeupFD[1]);
virObjectUnref(client);
virObjectUnref(sock);
return NULL;
}
......@@ -513,7 +515,6 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
if (!(ret = virNetClientNew(sock, NULL)))
goto cleanup;
sock = NULL;
cleanup:
VIR_FREE(command);
......@@ -522,7 +523,6 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
VIR_FREE(homedir);
VIR_FREE(confdir);
VIR_FREE(nc);
virObjectUnref(sock);
return ret;
no_memory:
......@@ -619,7 +619,6 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
if (!(ret = virNetClientNew(sock, NULL)))
goto cleanup;
sock = NULL;
cleanup:
VIR_FREE(command);
......@@ -628,7 +627,6 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
VIR_FREE(homedir);
VIR_FREE(confdir);
VIR_FREE(nc);
virObjectUnref(sock);
return ret;
no_memory:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册