Sfoglia il codice sorgente

* use a try..finally block to protect against memory leaks if the comparison
callback function raises an exception in QuickSort_ItemList_Context

git-svn-id: trunk@41228 -

nickysn 6 anni fa
parent
commit
de80621e1e
1 ha cambiato i file con 5 aggiunte e 2 eliminazioni
  1. 5 2
      rtl/inc/sortbase.pp

+ 5 - 2
rtl/inc/sortbase.pp

@@ -237,8 +237,11 @@ begin
   if not Assigned(Items) or (ItemCount < 2) or (ItemSize < 1) then
     exit;
   GetMem(TempBuf, ItemSize);
-  QuickSort(0, ItemCount - 1);
-  FreeMem(TempBuf, ItemSize);
+  try
+    QuickSort(0, ItemCount - 1);
+  finally
+    FreeMem(TempBuf, ItemSize);
+  end;
 end;
 
 procedure QuickSort_ItemList_CustomItemExchanger_Context(