Phase 1a of SFTP re-engineering: fix the glaring memory and request
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 29 Jun 2003 14:47:14 +0000 (14:47 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 29 Jun 2003 14:47:14 +0000 (14:47 +0000)
ID leak in the previous checkin. Oops :-)

git-svn-id: svn://svn.tartarus.org/sgt/putty@3319 cda61777-01e9-0310-a592-d414129be87e

psftp.c
scp.c
sftp.c
sftp.h

diff --git a/psftp.c b/psftp.c
index 71d5747..484d153 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -65,7 +65,7 @@ char *canonify(char *name)
     sftp_register(req = fxp_realpath_send(fullname));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    canonname = fxp_realpath_recv(pktin);
+    canonname = fxp_realpath_recv(pktin, rreq);
 
     if (canonname) {
        sfree(fullname);
@@ -126,7 +126,7 @@ char *canonify(char *name)
        }
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       canonname = fxp_realpath_recv(pktin);
+       canonname = fxp_realpath_recv(pktin, rreq);
 
        if (!canonname)
            return fullname;           /* even that failed; give up */
@@ -235,7 +235,7 @@ int sftp_cmd_ls(struct sftp_command *cmd)
     sftp_register(req = fxp_opendir_send(cdir));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    dirh = fxp_opendir_recv(pktin);
+    dirh = fxp_opendir_recv(pktin, rreq);
 
     if (dirh == NULL) {
        printf("Unable to open %s: %s\n", dir, fxp_error());
@@ -248,7 +248,7 @@ int sftp_cmd_ls(struct sftp_command *cmd)
            sftp_register(req = fxp_readdir_send(dirh));
            rreq = sftp_find_request(pktin = sftp_recv());
            assert(rreq == req);
-           names = fxp_readdir_recv(pktin);
+           names = fxp_readdir_recv(pktin, rreq);
 
            if (names == NULL) {
                if (fxp_error_type() == SSH_FX_EOF)
@@ -274,7 +274,7 @@ int sftp_cmd_ls(struct sftp_command *cmd)
        sftp_register(req = fxp_close_send(dirh));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       fxp_close_recv(pktin);
+       fxp_close_recv(pktin, rreq);
 
        /*
         * Now we have our filenames. Sort them by actual file
@@ -326,7 +326,7 @@ int sftp_cmd_cd(struct sftp_command *cmd)
     sftp_register(req = fxp_opendir_send(dir));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    dirh = fxp_opendir_recv(pktin);
+    dirh = fxp_opendir_recv(pktin, rreq);
 
     if (!dirh) {
        printf("Directory %s: %s\n", dir, fxp_error());
@@ -337,7 +337,7 @@ int sftp_cmd_cd(struct sftp_command *cmd)
     sftp_register(req = fxp_close_send(dirh));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    fxp_close_recv(pktin);
+    fxp_close_recv(pktin, rreq);
 
     sfree(pwd);
     pwd = dir;
@@ -397,7 +397,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart)
     sftp_register(req = fxp_open_send(fname, SSH_FXF_READ));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    fh = fxp_open_recv(pktin);
+    fh = fxp_open_recv(pktin, rreq);
 
     if (!fh) {
        printf("%s: %s\n", fname, fxp_error());
@@ -417,7 +417,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart)
        sftp_register(req = fxp_close_send(fh));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       fxp_close_recv(pktin);
+       fxp_close_recv(pktin, rreq);
 
        sfree(fname);
        return 0;
@@ -448,7 +448,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart)
        sftp_register(req = fxp_read_send(fh, offset, sizeof(buffer)));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       len = fxp_read_recv(pktin, buffer, sizeof(buffer));
+       len = fxp_read_recv(pktin, rreq, buffer, sizeof(buffer));
 
        if ((len == -1 && fxp_error_type() == SSH_FX_EOF) || len == 0)
            break;
@@ -480,7 +480,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart)
     sftp_register(req = fxp_close_send(fh));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    fxp_close_recv(pktin);
+    fxp_close_recv(pktin, rreq);
 
     sfree(fname);
 
@@ -544,7 +544,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart)
     }
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    fh = fxp_open_recv(pktin);
+    fh = fxp_open_recv(pktin, rreq);
 
     if (!fh) {
        printf("%s: %s\n", outfname, fxp_error());
@@ -560,7 +560,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart)
        sftp_register(req = fxp_fstat_send(fh));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_fstat_recv(pktin, &attrs);
+       ret = fxp_fstat_recv(pktin, rreq, &attrs);
 
        if (!ret) {
            printf("read size of %s: %s\n", outfname, fxp_error());
@@ -609,7 +609,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart)
        sftp_register(req = fxp_write_send(fh, buffer, offset, len));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_write_recv(pktin);
+       ret = fxp_write_recv(pktin, rreq);
 
        if (!ret) {
            printf("error while writing: %s\n", fxp_error());
@@ -622,7 +622,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart)
     sftp_register(req = fxp_close_send(fh));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    fxp_close_recv(pktin);
+    fxp_close_recv(pktin, rreq);
 
     fclose(fp);
     sfree(outfname);
@@ -664,7 +664,7 @@ int sftp_cmd_mkdir(struct sftp_command *cmd)
     sftp_register(req = fxp_mkdir_send(dir));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    result = fxp_mkdir_recv(pktin);
+    result = fxp_mkdir_recv(pktin, rreq);
 
     if (!result) {
        printf("mkdir %s: %s\n", dir, fxp_error());
@@ -702,7 +702,7 @@ int sftp_cmd_rmdir(struct sftp_command *cmd)
     sftp_register(req = fxp_rmdir_send(dir));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    result = fxp_rmdir_recv(pktin);
+    result = fxp_rmdir_recv(pktin, rreq);
 
     if (!result) {
        printf("rmdir %s: %s\n", dir, fxp_error());
@@ -740,7 +740,7 @@ int sftp_cmd_rm(struct sftp_command *cmd)
     sftp_register(req = fxp_remove_send(fname));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    result = fxp_remove_recv(pktin);
+    result = fxp_remove_recv(pktin, rreq);
 
     if (!result) {
        printf("rm %s: %s\n", fname, fxp_error());
@@ -783,7 +783,7 @@ int sftp_cmd_mv(struct sftp_command *cmd)
     sftp_register(req = fxp_rename_send(srcfname, dstfname));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    result = fxp_rename_recv(pktin);
+    result = fxp_rename_recv(pktin, rreq);
 
     if (!result) {
        char const *error = fxp_error();
@@ -798,7 +798,7 @@ int sftp_cmd_mv(struct sftp_command *cmd)
        sftp_register(req = fxp_stat_send(dstfname));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       result = fxp_stat_recv(pktin, &attrs);
+       result = fxp_stat_recv(pktin, rreq, &attrs);
 
        if (result &&
            (attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS) &&
@@ -818,7 +818,7 @@ int sftp_cmd_mv(struct sftp_command *cmd)
                sftp_register(req = fxp_rename_send(srcfname, dstfname));
                rreq = sftp_find_request(pktin = sftp_recv());
                assert(rreq == req);
-               result = fxp_rename_recv(pktin);
+               result = fxp_rename_recv(pktin, rreq);
 
                error = result ? NULL : fxp_error();
            }
@@ -970,7 +970,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
     sftp_register(req = fxp_stat_send(fname));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    result = fxp_stat_recv(pktin, &attrs);
+    result = fxp_stat_recv(pktin, rreq, &attrs);
 
     if (!result || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) {
        printf("get attrs for %s: %s\n", fname,
@@ -988,7 +988,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
     sftp_register(req = fxp_setstat_send(fname, attrs));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    result = fxp_setstat_recv(pktin);
+    result = fxp_setstat_recv(pktin, rreq);
 
     if (!result) {
        printf("set attrs for %s: %s\n", fname, fxp_error());
@@ -1498,7 +1498,7 @@ static int do_sftp_init(void)
     sftp_register(req = fxp_realpath_send("."));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    homedir = fxp_realpath_recv(pktin);
+    homedir = fxp_realpath_recv(pktin, rreq);
 
     if (!homedir) {
        fprintf(stderr,
diff --git a/scp.c b/scp.c
index f146bd7..8c05c97 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -775,7 +775,7 @@ void scp_sftp_listdir(char *dirname)
     sftp_register(req = fxp_opendir_send(dirname));
     rreq = sftp_find_request(pktin = sftp_recv());
     assert(rreq == req);
-    dirh = fxp_opendir_recv(pktin);
+    dirh = fxp_opendir_recv(pktin, rreq);
 
     if (dirh == NULL) {
        printf("Unable to open %s: %s\n", dirname, fxp_error());
@@ -788,7 +788,7 @@ void scp_sftp_listdir(char *dirname)
            sftp_register(req = fxp_readdir_send(dirh));
            rreq = sftp_find_request(pktin = sftp_recv());
            assert(rreq == req);
-           names = fxp_readdir_recv(pktin);
+           names = fxp_readdir_recv(pktin, rreq);
 
            if (names == NULL) {
                if (fxp_error_type() == SSH_FX_EOF)
@@ -815,7 +815,7 @@ void scp_sftp_listdir(char *dirname)
        sftp_register(req = fxp_close_send(dirh));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       fxp_close_recv(pktin);
+       fxp_close_recv(pktin, rreq);
 
        /*
         * Now we have our filenames. Sort them by actual file
@@ -874,7 +874,7 @@ void scp_source_setup(char *target, int shouldbedir)
        sftp_register(req = fxp_stat_send(target));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_stat_recv(pktin, &attrs);
+       ret = fxp_stat_recv(pktin, rreq, &attrs);
 
        if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS))
            scp_sftp_targetisdir = 0;
@@ -936,7 +936,7 @@ int scp_send_filename(char *name, unsigned long size, int modes)
                                          SSH_FXF_CREAT | SSH_FXF_TRUNC));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       scp_sftp_filehandle = fxp_open_recv(pktin);
+       scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
 
        if (!scp_sftp_filehandle) {
            tell_user(stderr, "pscp: unable to open %s: %s",
@@ -972,7 +972,7 @@ int scp_send_filedata(char *data, int len)
                                           data, scp_sftp_fileoffset, len));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_write_recv(pktin);
+       ret = fxp_write_recv(pktin, rreq);
 
        if (!ret) {
            tell_user(stderr, "error while writing: %s\n", fxp_error());
@@ -1018,7 +1018,7 @@ int scp_send_finish(void)
            sftp_register(req = fxp_fsetstat_send(scp_sftp_filehandle, attrs));
            rreq = sftp_find_request(pktin = sftp_recv());
            assert(rreq == req);
-           ret = fxp_fsetstat_recv(pktin);
+           ret = fxp_fsetstat_recv(pktin, rreq);
            if (!ret) {
                tell_user(stderr, "unable to set file times: %s\n", fxp_error());
                errs++;
@@ -1027,7 +1027,7 @@ int scp_send_finish(void)
        sftp_register(req = fxp_close_send(scp_sftp_filehandle));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       fxp_close_recv(pktin);
+       fxp_close_recv(pktin, rreq);
        scp_has_times = 0;
        return 0;
     } else {
@@ -1076,7 +1076,7 @@ int scp_send_dirname(char *name, int modes)
        sftp_register(req = fxp_mkdir_send(fullname));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_mkdir_recv(pktin);
+       ret = fxp_mkdir_recv(pktin, rreq);
 
        if (!ret)
            err = fxp_error();
@@ -1086,7 +1086,7 @@ int scp_send_dirname(char *name, int modes)
        sftp_register(req = fxp_stat_send(fullname));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_stat_recv(pktin, &attrs);
+       ret = fxp_stat_recv(pktin, rreq, &attrs);
 
        if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS) ||
            !(attrs.permissions & 0040000)) {
@@ -1308,7 +1308,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
        sftp_register(req = fxp_stat_send(fname));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       ret = fxp_stat_recv(pktin, &attrs);
+       ret = fxp_stat_recv(pktin, rreq, &attrs);
 
        if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) {
            tell_user(stderr, "unable to identify %s: %s", fname,
@@ -1364,7 +1364,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
            sftp_register(req = fxp_opendir_send(fname));
            rreq = sftp_find_request(pktin = sftp_recv());
            assert(rreq == req);
-           dirhandle = fxp_opendir_recv(pktin);
+           dirhandle = fxp_opendir_recv(pktin, rreq);
 
            if (!dirhandle) {
                tell_user(stderr, "scp: unable to open directory %s: %s",
@@ -1381,7 +1381,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
                sftp_register(req = fxp_readdir_send(dirhandle));
                rreq = sftp_find_request(pktin = sftp_recv());
                assert(rreq == req);
-               names = fxp_readdir_recv(pktin);
+               names = fxp_readdir_recv(pktin, rreq);
 
                if (names == NULL) {
                    if (fxp_error_type() == SSH_FX_EOF)
@@ -1409,7 +1409,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
            sftp_register(req = fxp_close_send(dirhandle));
            rreq = sftp_find_request(pktin = sftp_recv());
            assert(rreq == req);
-           fxp_close_recv(pktin);
+           fxp_close_recv(pktin, rreq);
 
            newitem = snew(struct scp_sftp_dirstack);
            newitem->next = scp_sftp_dirstack_head;
@@ -1557,7 +1557,7 @@ int scp_accept_filexfer(void)
        sftp_register(req = fxp_open_send(scp_sftp_currentname, SSH_FXF_READ));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       scp_sftp_filehandle = fxp_open_recv(pktin);
+       scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
 
        if (!scp_sftp_filehandle) {
            tell_user(stderr, "pscp: unable to open %s: %s",
@@ -1585,7 +1585,7 @@ int scp_recv_filedata(char *data, int len)
                                          scp_sftp_fileoffset, len));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       actuallen = fxp_read_recv(pktin, data, len);
+       actuallen = fxp_read_recv(pktin, rreq, data, len);
 
        if (actuallen == -1 && fxp_error_type() != SSH_FX_EOF) {
            tell_user(stderr, "pscp: error while reading: %s", fxp_error());
@@ -1612,7 +1612,7 @@ int scp_finish_filerecv(void)
        sftp_register(req = fxp_close_send(scp_sftp_filehandle));
        rreq = sftp_find_request(pktin = sftp_recv());
        assert(rreq == req);
-       fxp_close_recv(pktin);
+       fxp_close_recv(pktin, rreq);
        return 0;
     } else {
        back->send(backhandle, "", 1);
diff --git a/sftp.c b/sftp.c
index 265b4a2..e19c985 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -354,6 +354,8 @@ struct sftp_request *sftp_find_request(struct sftp_packet *pktin)
        return NULL;
     }
 
+    del234(sftp_requests, req);
+
     return req;
 }
 
@@ -488,8 +490,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 +539,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 +583,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 +630,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 +651,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 +676,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 +701,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 +727,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 +756,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 +785,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 +817,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 +845,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 +880,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 +923,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 +972,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;
diff --git a/sftp.h b/sftp.h
index fd3ec71..77aa2d9 100644 (file)
--- a/sftp.h
+++ b/sftp.h
@@ -108,86 +108,92 @@ int fxp_init(void);
  * with a separating slash, unless the second is NULL.
  */
 struct sftp_request *fxp_realpath_send(char *path);
-char *fxp_realpath_recv(struct sftp_packet *pktin);
+char *fxp_realpath_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Open a file.
  */
 struct sftp_request *fxp_open_send(char *path, int type);
-struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin);
+struct fxp_handle *fxp_open_recv(struct sftp_packet *pktin,
+                                struct sftp_request *req);
 
 /*
  * Open a directory.
  */
 struct sftp_request *fxp_opendir_send(char *path);
-struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin);
+struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin,
+                                   struct sftp_request *req);
 
 /*
  * Close a file/dir.
  */
 struct sftp_request *fxp_close_send(struct fxp_handle *handle);
-void fxp_close_recv(struct sftp_packet *pktin);
+void fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Make a directory.
  */
 struct sftp_request *fxp_mkdir_send(char *path);
-int fxp_mkdir_recv(struct sftp_packet *pktin);
+int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Remove a directory.
  */
 struct sftp_request *fxp_rmdir_send(char *path);
-int fxp_rmdir_recv(struct sftp_packet *pktin);
+int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Remove a file.
  */
 struct sftp_request *fxp_remove_send(char *fname);
-int fxp_remove_recv(struct sftp_packet *pktin);
+int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Rename a file.
  */
 struct sftp_request *fxp_rename_send(char *srcfname, char *dstfname);
-int fxp_rename_recv(struct sftp_packet *pktin);
+int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Return file attributes.
  */
 struct sftp_request *fxp_stat_send(char *fname);
-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);
 struct sftp_request *fxp_fstat_send(struct fxp_handle *handle);
-int fxp_fstat_recv(struct sftp_packet *pktin, struct fxp_attrs *attrs);
+int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req,
+                  struct fxp_attrs *attrs);
 
 /*
  * Set file attributes.
  */
 struct sftp_request *fxp_setstat_send(char *fname, struct fxp_attrs attrs);
-int fxp_setstat_recv(struct sftp_packet *pktin);
+int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
 struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle,
                                       struct fxp_attrs attrs);
-int fxp_fsetstat_recv(struct sftp_packet *pktin);
+int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Read from a file.
  */
 struct sftp_request *fxp_read_send(struct fxp_handle *handle,
                                   uint64 offset, int len);
-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);
 
 /*
  * Write to a file. Returns 0 on error, 1 on OK.
  */
 struct sftp_request *fxp_write_send(struct fxp_handle *handle,
                                    char *buffer, uint64 offset, int len);
-int fxp_write_recv(struct sftp_packet *pktin);
+int fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req);
 
 /*
  * Read from a directory.
  */
 struct sftp_request *fxp_readdir_send(struct fxp_handle *handle);
-struct fxp_names *fxp_readdir_recv(struct sftp_packet *pktin);
+struct fxp_names *fxp_readdir_recv(struct sftp_packet *pktin,
+                                  struct sftp_request *req);
 
 /*
  * Free up an fxp_names structure.