From 8c0294db66ea8f7a7e697e58f3764cef5c47a019 Mon Sep 17 00:00:00 2001 From: liuzl Date: Fri, 26 Aug 2011 13:47:35 +0200 Subject: [PATCH] libssh2_sftp_seek64: flush packetlist and buffered data When seeking to a new position, flush the packetlist and buffered data to prevent already received or pending data to wrongly get used when sftp-reading from the new offset within the file. --- src/sftp.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sftp.c b/src/sftp.c index 76ffaaf..297dfa4 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1859,8 +1859,18 @@ libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *hnd, LIBSSH2_API void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset) { - if(handle) + if(handle) { handle->u.file.offset = handle->u.file.offset_sent = offset; + /* discard all pending requests and currently read data */ + sftp_packetlist_flush(handle); + + /* free the left received buffered data */ + if (handle->u.file.data_left) { + LIBSSH2_FREE(handle->sftp->channel->session, handle->u.file.data); + handle->u.file.data_left = handle->u.file.data_len = 0; + handle->u.file.data = NULL; + } + } } /* libssh2_sftp_seek