From: Simon Tatham Date: Sat, 20 Dec 2014 18:42:22 +0000 (+0000) Subject: Fix a handle leak in Windows PSFTP. X-Git-Tag: 0.64~12 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=02dd708116bc5a5ece8041ddbd7fdca65c3f135d;p=PuTTY.git Fix a handle leak in Windows PSFTP. We were checking the return value of CreateThread for validity, but not keeping it to free afterwards if it _was_ valid. Also, we weren't closing ctx->event in the valid case either. Patch due to Tim Kosse. --- diff --git a/windows/winsftp.c b/windows/winsftp.c index f37ef243..d061b514 100644 --- a/windows/winsftp.c +++ b/windows/winsftp.c @@ -696,6 +696,7 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok) int ret; struct command_read_ctx actx, *ctx = &actx; DWORD threadid; + HANDLE hThread; fputs(prompt, stdout); fflush(stdout); @@ -712,8 +713,9 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok) ctx->event = CreateEvent(NULL, FALSE, FALSE, NULL); ctx->line = NULL; - if (!CreateThread(NULL, 0, command_read_thread, - ctx, 0, &threadid)) { + hThread = CreateThread(NULL, 0, command_read_thread, ctx, 0, &threadid); + if (!hThread) { + CloseHandle(ctx->event); fprintf(stderr, "Unable to create command input thread\n"); cleanup_exit(1); } @@ -725,6 +727,9 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok) assert(ret >= 0); } while (ret == 0); + CloseHandle(hThread); + CloseHandle(ctx->event); + return ctx->line; }