Skip to content

Commit

Permalink
Bug 2235: Failure when connection is lost while reading remote direct…
Browse files Browse the repository at this point in the history
…ory with SFTP protocol

https://winscp.net/tracker/2235

Source commit: fe8a892f071720efcd0c4e202cbad0cad920427d
  • Loading branch information
martinprikryl committed Oct 31, 2023
1 parent 1550537 commit ddca779
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 13 additions & 8 deletions source/core/SftpFileSystem.cpp
Expand Up @@ -1916,22 +1916,33 @@ __fastcall TSFTPFileSystem::TSFTPFileSystem(TTerminal * ATerminal,
__fastcall TSFTPFileSystem::~TSFTPFileSystem()
{
delete FSupport;
ResetConnection();
NoPacketReservations();
delete FPacketReservations;
delete FFixedPaths;
delete FSecureShell;
}
//---------------------------------------------------------------------------
void __fastcall TSFTPFileSystem::Open()
{
NoPacketReservations();
ResetConnection();
// this is used for reconnects only
FSecureShell->Open();
}
//---------------------------------------------------------------------------
void TSFTPFileSystem::NoPacketReservations()
{
// After closing, we can only possibly have "discard" reservations of the not-read responses to the last requests
// (typocally to SSH_FXP_CLOSE)
for (int i = 0; i < FPacketReservations->Count; i++)
{
DebugAssert(FPacketReservations->Items[i] == NULL);
}
}
//---------------------------------------------------------------------------
void __fastcall TSFTPFileSystem::Close()
{
FSecureShell->Close();
ResetConnection();
}
//---------------------------------------------------------------------------
bool __fastcall TSFTPFileSystem::GetActive()
Expand Down Expand Up @@ -2050,12 +2061,6 @@ void __fastcall TSFTPFileSystem::Idle()
//---------------------------------------------------------------------------
void __fastcall TSFTPFileSystem::ResetConnection()
{
// there must be no valid packet reservation at the end
for (int i = 0; i < FPacketReservations->Count; i++)
{
DebugAssert(FPacketReservations->Items[i] == NULL);
delete (TSFTPPacket *)FPacketReservations->Items[i];
}
FPacketReservations->Clear();
FPacketNumbers = VarArrayCreate(OPENARRAY(int, (0, 1)), varLongWord);
FNotLoggedRequests.clear();
Expand Down
1 change: 1 addition & 0 deletions source/core/SftpFileSystem.h
Expand Up @@ -199,6 +199,7 @@ friend class TSFTPBusy;
TFileOperationProgressType * OperationProgress);
bool __fastcall DoesFileLookLikeSymLink(TRemoteFile * File);
void DoCloseRemoteIfOpened(const RawByteString & Handle);
void NoPacketReservations();
};
//---------------------------------------------------------------------------
#endif // SftpFileSystemH

0 comments on commit ddca779

Please sign in to comment.