Oops. Fix a bug in my `keyfile-diagnostic' work which caused SSH-2 key loading
[u/mdw/putty] / sftp.c
diff --git a/sftp.c b/sftp.c
index 265b4a2..b9dc44b 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -67,10 +67,12 @@ static struct sftp_packet *sftp_pkt_init(int pkt_type)
     sftp_pkt_addbyte(pkt, (unsigned char) pkt_type);
     return pkt;
 }
+/*
 static void sftp_pkt_addbool(struct sftp_packet *pkt, unsigned char value)
 {
     sftp_pkt_adddata(pkt, &value, 1);
 }
+*/
 static void sftp_pkt_adduint32(struct sftp_packet *pkt,
                               unsigned long value)
 {
@@ -282,7 +284,6 @@ static tree234 *sftp_requests;
 
 static struct sftp_request *sftp_alloc_request(void)
 {
-    const unsigned CHANNEL_NUMBER_OFFSET = 256;
     unsigned low, high, mid;
     int tsize;
     struct sftp_request *r;
@@ -296,7 +297,7 @@ static struct sftp_request *sftp_alloc_request(void)
      * B-tree to find the largest ID which is in a contiguous
      * sequence from the beginning. (Precisely everything in that
      * sequence must have ID equal to its tree index plus
-     * SEQUENCE_NUMBER_OFFSET.)
+     * REQUEST_ID_OFFSET.)
      */
     tsize = count234(sftp_requests);
 
@@ -354,6 +355,8 @@ struct sftp_request *sftp_find_request(struct sftp_packet *pktin)
        return NULL;
     }
 
+    del234(sftp_requests, req);
+
     return req;
 }
 
@@ -488,8 +491,10 @@ struct sftp_request *fxp_realpath_send(char *path)
     return req;
 }
 
-char *fxp_realpath_recv(struct sftp_packet *pktin)
+char *fxp_realpath_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
+    sfree(req);
+
     if (pktin->type == SSH_FXP_NAME) {
        int count;
        char *path;
@@ -535,8 +540,11 @@ struct sftp_request *fxp_open_send(char *path, int type)
     return req;
 }
 
-struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin)
+struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin,
+                                struct sftp_request *req)
 {
+    sfree(req);
+
     if (pktin->type == SSH_FXP_HANDLE) {
        char *hstring;
        struct fxp_handle *handle;
@@ -576,8 +584,10 @@ struct sftp_request *fxp_opendir_send(char *path)
     return req;
 }
 
-struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin)
+struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin,
+                                   struct sftp_request *req)
 {
+    sfree(req);
     if (pktin->type == SSH_FXP_HANDLE) {
        char *hstring;
        struct fxp_handle *handle;
@@ -621,8 +631,9 @@ struct sftp_request *fxp_close_send(struct fxp_handle *handle)
     return req;
 }
 
-void fxp_close_recv(struct sftp_packet *pktin)
+void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
+    sfree(req);
     fxp_got_status(pktin);
     sftp_pkt_free(pktin);
 }
@@ -641,9 +652,11 @@ struct sftp_request *fxp_mkdir_send(char *path)
     return req;
 }
 
-int fxp_mkdir_recv(struct sftp_packet *pktin)
+int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
-    int id = fxp_got_status(pktin);
+    int id;
+    sfree(req);
+    id = fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     if (id != 1) {
        return 0;
@@ -664,9 +677,11 @@ struct sftp_request *fxp_rmdir_send(char *path)
     return req;
 }
 
-int fxp_rmdir_recv(struct sftp_packet *pktin)
+int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
-    int id = fxp_got_status(pktin);
+    int id;
+    sfree(req);
+    id = fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     if (id != 1) {
        return 0;
@@ -687,9 +702,11 @@ struct sftp_request *fxp_remove_send(char *fname)
     return req;
 }
 
-int fxp_remove_recv(struct sftp_packet *pktin)
+int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
-    int id = fxp_got_status(pktin);
+    int id;
+    sfree(req);
+    id = fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     if (id != 1) {
        return 0;
@@ -711,9 +728,11 @@ struct sftp_request *fxp_rename_send(char *srcfname, char *dstfname)
     return req;
 }
 
-int fxp_rename_recv(struct sftp_packet *pktin)
+int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
-    int id = fxp_got_status(pktin);
+    int id;
+    sfree(req);
+    id = fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     if (id != 1) {
        return 0;
@@ -738,8 +757,10 @@ struct sftp_request *fxp_stat_send(char *fname)
     return req;
 }
 
-int fxp_stat_recv(struct sftp_packet *pktin, struct fxp_attrs *attrs)
+int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req,
+                 struct fxp_attrs *attrs)
 {
+    sfree(req);
     if (pktin->type == SSH_FXP_ATTRS) {
        *attrs = sftp_pkt_getattrs(pktin);
         sftp_pkt_free(pktin);
@@ -765,9 +786,10 @@ struct sftp_request *fxp_fstat_send(struct fxp_handle *handle)
     return req;
 }
 
-int fxp_fstat_recv(struct sftp_packet *pktin,
+int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req,
                   struct fxp_attrs *attrs)
 {
+    sfree(req);
     if (pktin->type == SSH_FXP_ATTRS) {
        *attrs = sftp_pkt_getattrs(pktin);
         sftp_pkt_free(pktin);
@@ -796,9 +818,11 @@ struct sftp_request *fxp_setstat_send(char *fname, struct fxp_attrs attrs)
     return req;
 }
 
-int fxp_setstat_recv(struct sftp_packet *pktin)
+int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
-    int id = fxp_got_status(pktin);
+    int id;
+    sfree(req);
+    id = fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     if (id != 1) {
        return 0;
@@ -822,9 +846,11 @@ struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle,
     return req;
 }
 
-int fxp_fsetstat_recv(struct sftp_packet *pktin)
+int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
-    int id = fxp_got_status(pktin);
+    int id;
+    sfree(req);
+    id = fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     if (id != 1) {
        return 0;
@@ -855,8 +881,10 @@ struct sftp_request *fxp_read_send(struct fxp_handle *handle,
     return req;
 }
 
-int fxp_read_recv(struct sftp_packet *pktin, char *buffer, int len)
+int fxp_read_recv(struct sftp_packet *pktin, struct sftp_request *req,
+                 char *buffer, int len)
 {
+    sfree(req);
     if (pktin->type == SSH_FXP_DATA) {
        char *str;
        int rlen;
@@ -896,8 +924,10 @@ struct sftp_request *fxp_readdir_send(struct fxp_handle *handle)
     return req;
 }
 
-struct fxp_names *fxp_readdir_recv(struct sftp_packet *pktin)
+struct fxp_names *fxp_readdir_recv(struct sftp_packet *pktin,
+                                  struct sftp_request *req)
 {
+    sfree(req);
     if (pktin->type == SSH_FXP_NAME) {
        struct fxp_names *ret;
        int i;
@@ -943,8 +973,9 @@ struct sftp_request *fxp_write_send(struct fxp_handle *handle,
     return req;
 }
 
-int fxp_write_recv(struct sftp_packet *pktin)
+int fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req)
 {
+    sfree(req);
     fxp_got_status(pktin);
     sftp_pkt_free(pktin);
     return fxp_errtype == SSH_FX_OK;