From 6370782de7acd48cbfd916e963720915dc0cc92f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 7 Jun 2023 07:12:58 +0100 Subject: [PATCH 1/2] PSFTP: make the 'close' subcommand return success. A user points out that it always returned failure, even if it succeeded. As a result, a 'psftp -b' script of the form open this.host do stuff close open that.host do stuff close would terminate at the first 'close', believing it to have failed, and PSFTP would exit with a failure status. (Not only that, but there would be no error message indicating _why_ PSFTP had closed, because when a command returns failure it's expected to have printed an error message already.) --- psftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psftp.c b/psftp.c index d8b5c400..08796837 100644 --- a/psftp.c +++ b/psftp.c @@ -1024,7 +1024,7 @@ int sftp_cmd_close(struct sftp_command *cmd) } do_sftp_cleanup(); - return 0; + return 1; } void list_directory_from_sftp_warn_unsorted(void) From 05a6699939e83aeeb6b850e055401b6a98880d6e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 7 Jun 2023 07:14:29 +0100 Subject: [PATCH 2/2] PSFTP: fix memory leak opening two consecutive sessions. Testing the script described in the previous commit message, Leak Sanitiser pointed out that we didn't free the LogContext from the first connection, and overwrote the pointer variable with the one from the second. --- psftp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/psftp.c b/psftp.c index 08796837..587e2177 100644 --- a/psftp.c +++ b/psftp.c @@ -2386,6 +2386,10 @@ static void do_sftp_cleanup(void) sfree(homedir); homedir = NULL; } + if (psftp_logctx) { + log_free(psftp_logctx); + psftp_logctx = NULL; + } } int do_sftp(int mode, int modeflags, char *batchfile)