mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +00:00
Fix minor memory leak in psftp batch mode.
Spotted by Leak Sanitiser, while I was investigating the PSFTP /
proftpd issue mentioned in the previous commit (with ASan on as
usual).
The two very similar loops that read PSFTP commands from the
interactive prompt and a batch file differed in one respect: only one
of them remembered to free the command afterwards. Now I've moved the
freeing code out into a subroutine that both loops can use.
(cherry picked from commit bf0f323fb4
)
This commit is contained in:
parent
aed81648cc
commit
67ca9703be
19
psftp.c
19
psftp.c
@ -2316,6 +2316,16 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sftp_cmd_free(struct sftp_command *cmd)
|
||||||
|
{
|
||||||
|
if (cmd->words) {
|
||||||
|
for (size_t i = 0; i < cmd->nwords; i++)
|
||||||
|
sfree(cmd->words[i]);
|
||||||
|
sfree(cmd->words);
|
||||||
|
}
|
||||||
|
sfree(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
static int do_sftp_init(void)
|
static int do_sftp_init(void)
|
||||||
{
|
{
|
||||||
struct sftp_packet *pktin;
|
struct sftp_packet *pktin;
|
||||||
@ -2390,13 +2400,7 @@ int do_sftp(int mode, int modeflags, char *batchfile)
|
|||||||
if (!cmd)
|
if (!cmd)
|
||||||
break;
|
break;
|
||||||
ret = cmd->obey(cmd);
|
ret = cmd->obey(cmd);
|
||||||
if (cmd->words) {
|
sftp_cmd_free(cmd);
|
||||||
int i;
|
|
||||||
for(i = 0; i < cmd->nwords; i++)
|
|
||||||
sfree(cmd->words[i]);
|
|
||||||
sfree(cmd->words);
|
|
||||||
}
|
|
||||||
sfree(cmd);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2413,6 +2417,7 @@ int do_sftp(int mode, int modeflags, char *batchfile)
|
|||||||
if (!cmd)
|
if (!cmd)
|
||||||
break;
|
break;
|
||||||
ret = cmd->obey(cmd);
|
ret = cmd->obey(cmd);
|
||||||
|
sftp_cmd_free(cmd);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user