From 47208d263f3940ec65e7f94b9cc8f4c588234ac5 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 4 Oct 2009 17:29:18 +0200 Subject: Always check GetFileInfoSL() result This prevents crashes when file was deleted and included in selection for some operation. Also fix minor memory leaks... --- UCore.pas | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'UCore.pas') diff --git a/UCore.pas b/UCore.pas index 50f705f..5481bf9 100644 --- a/UCore.pas +++ b/UCore.pas @@ -682,6 +682,7 @@ var i: longint; Fr: Single; Response: integer; DeleteAll, SkipToNext: boolean; + x: PDataItemSL; begin SkipAll := False; @@ -695,12 +696,18 @@ begin if (not UpDir) and Selected then if IsDir and (not IsLnk) then Engine.FillDirFiles(CurrPath + String(FName), AList, 1) - else AList.Add(Engine.GetFileInfoSL(CurrPath + String(FName))); + else begin + x := Engine.GetFileInfoSL(CurrPath + String(FName)); + if x <> nil then AList.Add(x); + end; if (AList.Count = 0) and Assigned(SelectedItem) and (not SelectedItem^.UpDir) then with SelectedItem^ do if IsDir and (not IsLnk) then Engine.FillDirFiles(CurrPath + String(FName), AList, 1) - else AList.Add(Engine.GetFileInfoSL(CurrPath + String(FName))); + else begin + x := Engine.GetFileInfoSL(CurrPath + String(FName)); + if x <> nil then AList.Add(x); + end; if Engine.ChangeDir(CurrPath) <> 0 then DebugMsg(['*** WARNING: Cannot change to the origin location, strange behaviour might occur.']); Engine.ExplicitChDir('/'); @@ -1089,6 +1096,11 @@ var DefResponse: integer; // Global variables for this function then begin Response := DefResponse; Item := DestEngine.GetFileInfoSL(NewFilePath); + if Item = nil then begin + DebugMsg(['Something went terribly wrong during copy - Item := DestEngine.GetFileInfoSL(NewFilePath) == NULL!']); + Result := False; + Exit; + end; if Response = 0 then begin case ConfSizeFormat of 5: InfoLabelFormat := '%s, %s'; @@ -1989,6 +2001,7 @@ var i: longint; AList: TList; CurrPath: string; Fr: Single; + x: PDataItemSL; begin SkipAll := False; with SenderThread do begin @@ -2001,12 +2014,18 @@ begin if (not UpDir) and Selected then if IsDir and (not IsLnk) and ParamBool1 then Engine.FillDirFiles(CurrPath + String(FName), AList, 1) - else AList.Add(Engine.GetFileInfoSL(CurrPath + String(FName))); + else begin + x := Engine.GetFileInfoSL(CurrPath + String(FName)); + if x <> nil then AList.Add(x); + end; if (AList.Count = 0) and Assigned(SelectedItem) and (not SelectedItem^.UpDir) then with SelectedItem^ do if IsDir and (not IsLnk) and ParamBool1 then Engine.FillDirFiles(CurrPath + String(FName), AList, 1) - else AList.Add(Engine.GetFileInfoSL(CurrPath + String(FName))); + else begin + x := Engine.GetFileInfoSL(CurrPath + String(FName)); + if x <> nil then AList.Add(x); + end; Engine.ExplicitChDir('/'); SetProgress1Params(AList.Count); UpdateProgress1(0, '0 %'); @@ -2078,6 +2097,7 @@ var i: longint; AList: TList; CurrPath: string; Fr: Single; + x: PDataItemSL; begin SkipAll := False; with SenderThread do begin @@ -2090,12 +2110,18 @@ begin if (not UpDir) and Selected then if IsDir and (not IsLnk) and ParamBool1 then Engine.FillDirFiles(CurrPath + String(FName), AList, 1) - else AList.Add(Engine.GetFileInfoSL(CurrPath + String(FName))); + else begin + x := Engine.GetFileInfoSL(CurrPath + String(FName)); + if x <> nil then AList.Add(x); + end; if (AList.Count = 0) and Assigned(SelectedItem) and (not SelectedItem^.UpDir) then with SelectedItem^ do if IsDir and (not IsLnk) and ParamBool1 then Engine.FillDirFiles(CurrPath + String(FName), AList, 1) - else AList.Add(Engine.GetFileInfoSL(CurrPath + String(FName))); + else begin + x := Engine.GetFileInfoSL(CurrPath + String(FName)); + if x <> nil then AList.Add(x); + end; Engine.ExplicitChDir('/'); SetProgress1Params(AList.Count); UpdateProgress1(0, '0 %'); @@ -2256,6 +2282,10 @@ var Data: PDataItemSL; begin Result := False; Data := Engine.GetFileInfoSL(FileName); + if Data = nil then begin + Result := False; + Exit; + end; try AFSymlink := TFSymlink.Create(Application); AFSymlink.Caption := LANGFEditSymlink_Caption; -- cgit v1.2.3