X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/c2eb6cb7db654cc38c996be9c72f0e06e93b1c98..038ec85e825fc940c1387f64a88ae73b75f6822b:/unix/uxsftp.c diff --git a/unix/uxsftp.c b/unix/uxsftp.c index a92cfc9d..57f28416 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -443,7 +443,7 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok) fd_set rset, wset, xset; int i, fdcount, fdsize, *fdlist; int fd, fdstate, rwx, ret, maxfd; - long now = GETTICKCOUNT(); + unsigned long now = GETTICKCOUNT(); fdlist = NULL; fdcount = fdsize = 0; @@ -489,13 +489,17 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok) FD_SET_MAX(0, maxfd, rset); do { - long next, ticks; + unsigned long next, then; + long ticks; struct timeval tv, *ptv; if (run_timers(now, &next)) { - ticks = next - GETTICKCOUNT(); - if (ticks <= 0) - ticks = 1; /* just in case */ + then = now; + now = GETTICKCOUNT(); + if (now - then > next - then) + ticks = 0; + else + ticks = next - now; tv.tv_sec = ticks / 1000; tv.tv_usec = ticks % 1000 * 1000; ptv = &tv; @@ -561,6 +565,7 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok) ret = ssh_sftp_do_select(TRUE, no_fds_ok); if (ret < 0) { printf("connection died\n"); + sfree(buf); return NULL; /* woop woop */ } if (ret > 0) { @@ -571,10 +576,12 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok) ret = read(0, buf+buflen, 1); if (ret < 0) { perror("read"); + sfree(buf); return NULL; } if (ret == 0) { /* eof on stdin; no error, but no answer either */ + sfree(buf); return NULL; }