Fix a couple of code paths on which, if fxp_readdir returned an error,
[u/mdw/putty] / pscp.c
diff --git a/pscp.c b/pscp.c
index 93111d3..4c6aba7 100644 (file)
--- a/pscp.c
+++ b/pscp.c
@@ -765,7 +765,8 @@ void scp_sftp_listdir(char *dirname)
         * Now we have our filenames. Sort them by actual file
         * name, and then output the longname parts.
         */
-       qsort(ournames, nnames, sizeof(*ournames), sftp_ls_compare);
+        if (nnames > 0)
+            qsort(ournames, nnames, sizeof(*ournames), sftp_ls_compare);
 
        /*
         * And print them.
@@ -1347,6 +1348,11 @@ int scp_get_sink_action(struct scp_sink_action *act)
                        break;
                    tell_user(stderr, "scp: reading directory %s: %s\n",
                              fname, fxp_error());
+
+                    req = fxp_close_send(dirhandle);
+                    pktin = sftp_wait_for_reply(req);
+                    fxp_close_recv(pktin, req);
+
                    if (must_free_fname) sfree(fname);
                    sfree(ournames);
                    errs++;