]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Fix a handle leak in Windows PSFTP.
authorSimon Tatham <anakin@pobox.com>
Sat, 20 Dec 2014 18:42:22 +0000 (18:42 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 20 Dec 2014 18:48:30 +0000 (18:48 +0000)
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.

windows/winsftp.c

index f37ef2431236d056267dda4adcf51bfde8471b7a..d061b514843a56d66bbd8d6f4ed91e945b7aa89a 100644 (file)
@@ -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;
 }