Without this do_close() I get "Couldn't get handle: Failure" on every operation after N times through this failure path where N = 100 on OpenBSD and N = 200 on GNU/Linux. --- src/usr.bin/ssh/sftp-client.c.orig Sun Sep 16 00:55:52 2007 +++ src/usr.bin/ssh/sftp-client.c Mon Oct 15 10:12:50 2007 @@ -813,6 +813,7 @@ do_download(struct sftp_conn *conn, char if (local_fd == -1) { error("Couldn't open local file \"%s\" for writing: %s", local_path, strerror(errno)); + do_close(conn, handle, handle_len); buffer_free(&msg); xfree(handle); return(-1);