Browse Source

Bug 1684: Failure when canceling session reconnect (2nd)

https://winscp.net/tracker/1684

Source commit: 62b7f6a90ac109587d5c4eed7ca568313973f415
Martin Prikryl 7 years ago
parent
commit
ab0fe8e7d3

+ 0 - 5
source/core/Queue.cpp

@@ -2887,11 +2887,6 @@ bool __fastcall TTerminalThread::Release()
   {
     delete this;
   }
-  else
-  {
-    // only now has the owner released ownership of the thread, so we are safe to kill outselves.
-    Terminate();
-  }
   return Result;
 }
 //---------------------------------------------------------------------------

+ 15 - 20
source/forms/CustomScpExplorer.cpp

@@ -544,27 +544,22 @@ void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
   if (FTerminal != value)
   {
     TerminalChanging();
-    ReplaceTerminal(value);
-  }
-}
-//---------------------------------------------------------------------------
-void __fastcall TCustomScpExplorerForm::ReplaceTerminal(TTerminal * value)
-{
-  FTerminal = value;
-  bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
-  FAllowTransferPresetAutoSelect = false;
-  try
-  {
-    TerminalChanged();
-  }
-  __finally
-  {
-    FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
-  }
+    FTerminal = value;
+    bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
+    FAllowTransferPresetAutoSelect = false;
+    try
+    {
+      TerminalChanged();
+    }
+    __finally
+    {
+      FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
+    }
 
-  if (Terminal != NULL)
-  {
-    TransferPresetAutoSelect();
+    if (Terminal != NULL)
+    {
+      TransferPresetAutoSelect();
+    }
   }
 }
 //---------------------------------------------------------------------------

+ 0 - 1
source/forms/CustomScpExplorer.h

@@ -761,7 +761,6 @@ public:
   bool __fastcall CanPrivateKeyUpload();
   void __fastcall PrivateKeyUpload();
   bool __fastcall IsComponentPossible(Byte Component);
-  void __fastcall ReplaceTerminal(TTerminal * value);
 
   __property bool ComponentVisible[Byte Component] = { read = GetComponentVisible, write = SetComponentVisible };
   __property bool EnableFocusedOperation[TOperationSide Side] = { read = GetEnableFocusedOperation, index = 0 };

+ 4 - 2
source/windows/TerminalManager.cpp

@@ -279,9 +279,11 @@ void __fastcall TTerminalManager::DoConnectTerminal(TTerminal * Terminal, bool R
           Items[ActiveTerminalIndex] = Terminal;
           OwnsObjects = true;
           FActiveTerminal = Terminal;
-          // Not to call TerminalChanging() => UpdateTerminal() on a terminal that might be already released
-          FScpExplorer->ReplaceTerminal(Terminal);
+          TerminalReady();
         }
+        // Now we do not have any reference to an abandoned terminal, so we can safely allow the thread
+        // to complete its task and destroy the terminal afterwards.
+        TerminalThread->Terminate();
 
         // When abandoning cancelled terminal, DoInformation(Phase = 0) does not make it to TerminalInformation handler.
         if (DebugAlwaysTrue(FAuthenticating > 0))