瀏覽代碼

Memory leak

Source commit: fc7c960d0bfc21c067fae53eba3fa7b679fae8fe
Martin Prikryl 4 年之前
父節點
當前提交
00daaf7b98
共有 1 個文件被更改,包括 38 次插入38 次删除
  1. 38 38
      source/core/Script.cpp

+ 38 - 38
source/core/Script.cpp

@@ -574,9 +574,9 @@ TStrings * __fastcall TScript::CreateFileList(TScriptProcParams * Parameters, in
   int End, TFileListType ListType)
 {
   TStrings * Result = new TStringList();
-  TStrings * FileLists = NULL;
   try
   {
+    TStrings * FileLists = NULL;
     try
     {
       for (int i = Start; i <= End; i++)
@@ -673,58 +673,58 @@ TStrings * __fastcall TScript::CreateFileList(TScriptProcParams * Parameters, in
         }
       }
     }
-    catch(...)
-    {
-      FreeFileList(Result);
-      throw;
-    }
-  }
-  __finally
-  {
-    if (FileLists != NULL)
+    __finally
     {
-      for (int i = 0; i < FileLists->Count; i++)
+      if (FileLists != NULL)
       {
-        delete FileLists->Objects[i];
+        for (int i = 0; i < FileLists->Count; i++)
+        {
+          delete FileLists->Objects[i];
+        }
+        delete FileLists;
       }
-      delete FileLists;
     }
-  }
-
-  if (FLAGSET(ListType, fltLatest) && (Result->Count > 1))
-  {
-    // otherwise we do not have TRemoteFile's
-    DebugAssert(FLAGSET(ListType, fltQueryServer));
-    int LatestIndex = 0;
 
-    for (int Index = 1; Index < Result->Count; Index++)
+    if (FLAGSET(ListType, fltLatest) && (Result->Count > 1))
     {
-      TRemoteFile * File = dynamic_cast<TRemoteFile *>(Result->Objects[Index]);
-      if (dynamic_cast<TRemoteFile *>(Result->Objects[LatestIndex])->Modification < File->Modification)
+      // otherwise we do not have TRemoteFile's
+      DebugAssert(FLAGSET(ListType, fltQueryServer));
+      int LatestIndex = 0;
+
+      for (int Index = 1; Index < Result->Count; Index++)
       {
-        LatestIndex = Index;
+        TRemoteFile * File = dynamic_cast<TRemoteFile *>(Result->Objects[Index]);
+        if (dynamic_cast<TRemoteFile *>(Result->Objects[LatestIndex])->Modification < File->Modification)
+        {
+          LatestIndex = Index;
+        }
       }
-    }
 
-    TRemoteFile * File = dynamic_cast<TRemoteFile *>(Result->Objects[LatestIndex]);
-    UnicodeString Path = Result->Strings[LatestIndex];
-    Result->Delete(LatestIndex);
-    FreeFiles(Result);
-    Result->Clear();
-    Result->AddObject(Path, File);
-  }
+      TRemoteFile * File = dynamic_cast<TRemoteFile *>(Result->Objects[LatestIndex]);
+      UnicodeString Path = Result->Strings[LatestIndex];
+      Result->Delete(LatestIndex);
+      FreeFiles(Result);
+      Result->Clear();
+      Result->AddObject(Path, File);
+    }
 
-  if (FLAGSET(ListType, fltOnlyFile))
-  {
-    for (int Index = 0; Index < Result->Count; Index++)
+    if (FLAGSET(ListType, fltOnlyFile))
     {
-      TRemoteFile * File = dynamic_cast<TRemoteFile *>(Result->Objects[Index]);
-      if (File->IsDirectory)
+      for (int Index = 0; Index < Result->Count; Index++)
       {
-        throw Exception(FMTLOAD(NOT_FILE_ERROR, (File->FileName)));
+        TRemoteFile * File = dynamic_cast<TRemoteFile *>(Result->Objects[Index]);
+        if (File->IsDirectory)
+        {
+          throw Exception(FMTLOAD(NOT_FILE_ERROR, (File->FileName)));
+        }
       }
     }
   }
+  catch (...)
+  {
+    FreeFileList(Result);
+    throw;
+  }
 
   return Result;
 }