mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
virnetsocket: Don't free virCommand in virNetSocketNewConnectCommand()
The aim of virNetSocketNewConnectCommand() is to execute passed command and attach socket pair/pipe to it so that client socket can be opened (this is used for connections with alternative transports, e.g. ssh). The virCommand is created in a caller and then passed to virNetSocketNewConnectCommand() where it is freed using virCommandFree(). This approach is wrong on two levels: 1) The deallocation happens on a different level than allocation, 2) There's a WIN32 stub that just reports an error and doesn't free the command. However, with g_autoptr() trickery the command can be freed in caller. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
d9afe162ab
commit
44d8324f13
@ -821,8 +821,6 @@ int virNetSocketNewConnectCommand(virCommand *cmd,
|
|||||||
if (!(*retsock = virNetSocketNew(NULL, NULL, true, sv[0], errfd[0], pid, false)))
|
if (!(*retsock = virNetSocketNew(NULL, NULL, true, sv[0], errfd[0], pid, false)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virCommandFree(cmd);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -832,7 +830,6 @@ int virNetSocketNewConnectCommand(virCommand *cmd,
|
|||||||
VIR_FORCE_CLOSE(errfd[1]);
|
VIR_FORCE_CLOSE(errfd[1]);
|
||||||
|
|
||||||
virCommandAbort(cmd);
|
virCommandAbort(cmd);
|
||||||
virCommandFree(cmd);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -856,7 +853,7 @@ int virNetSocketNewConnectSSH(const char *nodename,
|
|||||||
const char *command,
|
const char *command,
|
||||||
virNetSocket **retsock)
|
virNetSocket **retsock)
|
||||||
{
|
{
|
||||||
virCommand *cmd;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
|
|
||||||
*retsock = NULL;
|
*retsock = NULL;
|
||||||
|
|
||||||
@ -1154,7 +1151,7 @@ virNetSocketNewConnectLibssh(const char *host G_GNUC_UNUSED,
|
|||||||
int virNetSocketNewConnectExternal(const char **cmdargv,
|
int virNetSocketNewConnectExternal(const char **cmdargv,
|
||||||
virNetSocket **retsock)
|
virNetSocket **retsock)
|
||||||
{
|
{
|
||||||
virCommand *cmd;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
|
|
||||||
*retsock = NULL;
|
*retsock = NULL;
|
||||||
|
|
||||||
|
@ -388,7 +388,8 @@ static int testSocketCommandNormal(const void *data G_GNUC_UNUSED)
|
|||||||
char buf[100];
|
char buf[100];
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virCommand *cmd = virCommandNewArgList("/bin/cat", "/dev/zero", NULL);
|
g_autoptr(virCommand) cmd = virCommandNewArgList("/bin/cat", "/dev/zero", NULL);
|
||||||
|
|
||||||
virCommandAddEnvPassCommon(cmd);
|
virCommandAddEnvPassCommon(cmd);
|
||||||
|
|
||||||
if (virNetSocketNewConnectCommand(cmd, &csock) < 0)
|
if (virNetSocketNewConnectCommand(cmd, &csock) < 0)
|
||||||
@ -415,7 +416,8 @@ static int testSocketCommandFail(const void *data G_GNUC_UNUSED)
|
|||||||
virNetSocket *csock = NULL; /* Client socket */
|
virNetSocket *csock = NULL; /* Client socket */
|
||||||
char buf[100];
|
char buf[100];
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virCommand *cmd = virCommandNewArgList("/bin/cat", "/dev/does-not-exist", NULL);
|
g_autoptr(virCommand) cmd = virCommandNewArgList("/bin/cat", "/dev/does-not-exist", NULL);
|
||||||
|
|
||||||
virCommandAddEnvPassCommon(cmd);
|
virCommandAddEnvPassCommon(cmd);
|
||||||
|
|
||||||
if (virNetSocketNewConnectCommand(cmd, &csock) < 0)
|
if (virNetSocketNewConnectCommand(cmd, &csock) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user