Browse Source

Using unique_ptr instead of auto_ptr + Replacing use of auto_ptr, where unique_ptr cannot be used with plain pointers

Source commit: 0c397b15f93f20fcb52bdd7c8747aae8429f8b1e
Martin Prikryl 3 years ago
parent
commit
2fdcc0e6ad

+ 1 - 1
source/core/S3FileSystem.cpp

@@ -1735,7 +1735,7 @@ struct TLibS3TransferObjectDataCallbackData : TLibS3CallbackData
   UnicodeString FileName;
   TStream * Stream;
   TFileOperationProgressType * OperationProgress;
-  std::auto_ptr<Exception> Exception;
+  std::unique_ptr<Exception> Exception;
 };
 //---------------------------------------------------------------------------
 struct TLibS3PutObjectDataCallbackData : TLibS3TransferObjectDataCallbackData

+ 9 - 8
source/core/SecureShell.cpp

@@ -75,8 +75,8 @@ __fastcall TSecureShell::TSecureShell(TSessionUI* UI,
   FSimple = false;
   FCollectPrivateKeyUsage = false;
   FWaitingForData = 0;
-  FCallbackSet.reset(new callback_set());
-  memset(FCallbackSet.get(), 0, sizeof(callback_set));
+  FCallbackSet = new callback_set();
+  memset(FCallbackSet, 0, sizeof(*FCallbackSet));
   FCallbackSet->ready_event = INVALID_HANDLE_VALUE;
 }
 //---------------------------------------------------------------------------
@@ -89,6 +89,7 @@ __fastcall TSecureShell::~TSecureShell()
   }
   ResetConnection();
   CloseHandle(FSocketEvent);
+  delete FCallbackSet;
 }
 //---------------------------------------------------------------------------
 void __fastcall TSecureShell::ResetConnection()
@@ -626,7 +627,7 @@ void __fastcall TSecureShell::Init()
 //---------------------------------------------------------------------------
 struct callback_set * TSecureShell::GetCallbackSet()
 {
-  return FCallbackSet.get();
+  return FCallbackSet;
 }
 //---------------------------------------------------------------------------
 UnicodeString __fastcall TSecureShell::ConvertFromPutty(const char * Str, int Length)
@@ -1692,10 +1693,10 @@ void __fastcall TSecureShell::FreeBackend()
     FBackendHandle = NULL;
 
     // After destroying backend, ic_pktin_free should be the only remaining callback.
-    if (is_idempotent_callback_pending(FCallbackSet.get(), FCallbackSet->ic_pktin_free))
+    if (is_idempotent_callback_pending(FCallbackSet, FCallbackSet->ic_pktin_free))
     {
       // This releases the callback and should be noop otherwise.
-      run_toplevel_callbacks(FCallbackSet.get());
+      run_toplevel_callbacks(FCallbackSet);
     }
 
     sfree(FCallbackSet->ic_pktin_free);
@@ -1719,7 +1720,7 @@ void __fastcall TSecureShell::FreeBackend()
       while (count234(FCallbackSet->handlewaits_tree_real) > 0)
       {
         HandleWait * AHandleWait = static_cast<HandleWait *>(index234(FCallbackSet->handlewaits_tree_real, 0));
-        delete_handle_wait(FCallbackSet.get(), AHandleWait);
+        delete_handle_wait(FCallbackSet, AHandleWait);
       }
 
       freetree234(FCallbackSet->handlewaits_tree_real);
@@ -2035,7 +2036,7 @@ bool __fastcall TSecureShell::EventSelectLoop(unsigned int MSec, bool ReadEventR
           handle_wait_list_free(WaitList);
         }
         // It returns only busy handles, so the set can change with every call to run_toplevel_callbacks.
-        WaitList = get_handle_wait_list(FCallbackSet.get());
+        WaitList = get_handle_wait_list(FCallbackSet);
         DebugAssert(WaitList->nhandles < MAXIMUM_WAIT_OBJECTS);
         WaitList->handles[WaitList->nhandles] = FSocketEvent;
         WaitResult = WaitForMultipleObjects(WaitList->nhandles + 1, WaitList->handles, FALSE, TimeoutStep);
@@ -2056,7 +2057,7 @@ bool __fastcall TSecureShell::EventSelectLoop(unsigned int MSec, bool ReadEventR
 
       if (WaitResult < WAIT_OBJECT_0 + WaitList->nhandles)
       {
-        if (handle_wait_activate(FCallbackSet.get(), WaitList, WaitResult - WAIT_OBJECT_0))
+        if (handle_wait_activate(FCallbackSet, WaitList, WaitResult - WAIT_OBJECT_0))
         {
           Result = true;
         }

+ 1 - 1
source/core/SecureShell.h

@@ -72,7 +72,7 @@ private:
   bool FUtfStrings;
   DWORD FLastSendBufferUpdate;
   int FSendBuf;
-  std::auto_ptr<callback_set> FCallbackSet;
+  callback_set * FCallbackSet;
   ScpLogPolicy * FLogPolicy;
   ScpSeat * FSeat;
   LogContext * FLogCtx;

+ 3 - 3
source/core/SessionData.cpp

@@ -5379,7 +5379,7 @@ void __fastcall TStoredSessionList::ImportHostKeys(
   if (OpenHostKeysSubKey(SourceStorage, false) &&
       OpenHostKeysSubKey(TargetStorage, true))
   {
-    std::auto_ptr<TStringList> KeyList(new TStringList());
+    std::unique_ptr<TStringList> KeyList(new TStringList());
     SourceStorage->GetValueNames(KeyList.get());
 
     DebugAssert(Sessions != NULL);
@@ -5405,8 +5405,8 @@ void __fastcall TStoredSessionList::ImportHostKeys(
 void __fastcall TStoredSessionList::ImportHostKeys(
   const UnicodeString & SourceKey, TStoredSessionList * Sessions, bool OnlySelected)
 {
-  std::auto_ptr<THierarchicalStorage> TargetStorage(CreateHostKeysStorageForWritting());
-  std::auto_ptr<THierarchicalStorage> SourceStorage(new TRegistryStorage(SourceKey));
+  std::unique_ptr<THierarchicalStorage> TargetStorage(CreateHostKeysStorageForWritting());
+  std::unique_ptr<THierarchicalStorage> SourceStorage(new TRegistryStorage(SourceKey));
 
   ImportHostKeys(SourceStorage.get(), TargetStorage.get(), Sessions, OnlySelected);
 }

+ 1 - 1
source/forms/CustomScpExplorer.h

@@ -304,7 +304,7 @@ private:
   TTerminal * FFileFindTerminal;
   UnicodeString FFileColorsCurrent;
   bool FInvalid;
-  std::auto_ptr<TQueueFileList> FQueueFileList;
+  std::unique_ptr<TQueueFileList> FQueueFileList;
   bool FShowingChanged;
   bool FStarted;
   bool FUpdatingSessionTabs;

+ 1 - 1
source/windows/WinConfiguration.cpp

@@ -2814,7 +2814,7 @@ void __fastcall TWinConfiguration::UpdateEntryInJumpList(
 {
   try
   {
-    std::auto_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
+    std::unique_ptr<THierarchicalStorage> Storage(CreateConfigStorage());
     TAutoNestingCounter DontDecryptPasswordsCounter(FDontDecryptPasswords);
 
     Storage->AccessMode = smReadWrite;