mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 16:20:55 +02:00
* fixed AddDisk() in sysutils and dos units, and fixed memory leaks
related to this functionality, based on analysis/patch by Michael Kamburelis (mantis #9985) git-svn-id: trunk@12814 -
This commit is contained in:
parent
9e7efd7321
commit
f7003119d0
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -9645,6 +9645,8 @@ tests/webtbs/tw9894a.pp svneol=native#text/plain
|
|||||||
tests/webtbs/tw9897.pp svneol=native#text/plain
|
tests/webtbs/tw9897.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw9918.pp svneol=native#text/plain
|
tests/webtbs/tw9918.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw9919.pp -text
|
tests/webtbs/tw9919.pp -text
|
||||||
|
tests/webtbs/tw9985.pp svneol=native#text/plain
|
||||||
|
tests/webtbs/tw9985a.pp svneol=native#text/plain
|
||||||
tests/webtbs/ub1873.pp svneol=native#text/plain
|
tests/webtbs/ub1873.pp svneol=native#text/plain
|
||||||
tests/webtbs/ub1883.pp svneol=native#text/plain
|
tests/webtbs/ub1883.pp svneol=native#text/plain
|
||||||
tests/webtbs/uw0555.pp svneol=native#text/plain
|
tests/webtbs/uw0555.pp svneol=native#text/plain
|
||||||
|
@ -388,13 +388,13 @@ var
|
|||||||
Function AddDisk(const path:string) : byte;
|
Function AddDisk(const path:string) : byte;
|
||||||
begin
|
begin
|
||||||
if not (DriveStr[Drives]=nil) then
|
if not (DriveStr[Drives]=nil) then
|
||||||
FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
|
FreeMem(DriveStr[Drives]);
|
||||||
GetMem(DriveStr[Drives],length(Path)+1);
|
GetMem(DriveStr[Drives],length(Path)+1);
|
||||||
StrPCopy(DriveStr[Drives],path);
|
StrPCopy(DriveStr[Drives],path);
|
||||||
|
AddDisk:=Drives;
|
||||||
inc(Drives);
|
inc(Drives);
|
||||||
if Drives>26 then
|
if Drives>26 then
|
||||||
Drives:=4;
|
Drives:=4;
|
||||||
AddDisk:=Drives;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -424,6 +424,19 @@ Begin
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Procedure FreeDriveStr;
|
||||||
|
var
|
||||||
|
i: longint;
|
||||||
|
begin
|
||||||
|
for i:=low(drivestr) to high(drivestr) do
|
||||||
|
if assigned(drivestr[i]) then
|
||||||
|
begin
|
||||||
|
freemem(drivestr[i]);
|
||||||
|
drivestr[i]:=nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{******************************************************************************
|
{******************************************************************************
|
||||||
--- Findfirst FindNext ---
|
--- Findfirst FindNext ---
|
||||||
******************************************************************************}
|
******************************************************************************}
|
||||||
@ -895,4 +908,6 @@ End;
|
|||||||
--- Initialization ---
|
--- Initialization ---
|
||||||
******************************************************************************}
|
******************************************************************************}
|
||||||
|
|
||||||
|
Finalization
|
||||||
|
FreeDriveStr;
|
||||||
End.
|
End.
|
||||||
|
@ -705,19 +705,19 @@ Const
|
|||||||
'/.'
|
'/.'
|
||||||
);
|
);
|
||||||
var
|
var
|
||||||
Drives : byte;
|
Drives : byte = 4;
|
||||||
DriveStr : array[4..26] of pchar;
|
DriveStr : array[4..26] of pchar;
|
||||||
|
|
||||||
Function AddDisk(const path:string) : Byte;
|
Function AddDisk(const path:string) : Byte;
|
||||||
begin
|
begin
|
||||||
if not (DriveStr[Drives]=nil) then
|
if not (DriveStr[Drives]=nil) then
|
||||||
FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
|
FreeMem(DriveStr[Drives]);
|
||||||
GetMem(DriveStr[Drives],length(Path)+1);
|
GetMem(DriveStr[Drives],length(Path)+1);
|
||||||
StrPCopy(DriveStr[Drives],path);
|
StrPCopy(DriveStr[Drives],path);
|
||||||
|
Result:=Drives;
|
||||||
inc(Drives);
|
inc(Drives);
|
||||||
if Drives>26 then
|
if Drives>26 then
|
||||||
Drives:=4;
|
Drives:=4;
|
||||||
Result:=Drives;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -746,6 +746,20 @@ Begin
|
|||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
||||||
|
Procedure FreeDriveStr;
|
||||||
|
var
|
||||||
|
i: longint;
|
||||||
|
begin
|
||||||
|
for i:=low(drivestr) to high(drivestr) do
|
||||||
|
if assigned(drivestr[i]) then
|
||||||
|
begin
|
||||||
|
freemem(drivestr[i]);
|
||||||
|
drivestr[i]:=nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Function GetCurrentDir : String;
|
Function GetCurrentDir : String;
|
||||||
begin
|
begin
|
||||||
GetDir (0,Result);
|
GetDir (0,Result);
|
||||||
@ -1155,5 +1169,6 @@ Initialization
|
|||||||
InitInternational; { Initialize internationalization settings }
|
InitInternational; { Initialize internationalization settings }
|
||||||
SysConfigDir:='/etc'; { Initialize system config dir }
|
SysConfigDir:='/etc'; { Initialize system config dir }
|
||||||
Finalization
|
Finalization
|
||||||
|
FreeDriveStr;
|
||||||
DoneExceptions;
|
DoneExceptions;
|
||||||
end.
|
end.
|
||||||
|
25
tests/webtbs/tw9985.pp
Normal file
25
tests/webtbs/tw9985.pp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{ %opt=-gh }
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
|
||||||
|
uses SysUtils;
|
||||||
|
|
||||||
|
var
|
||||||
|
DiskNum: Byte;
|
||||||
|
begin
|
||||||
|
HaltOnNotReleased := true;
|
||||||
|
Writeln(DiskFree(3), '/', DiskSize(3));
|
||||||
|
|
||||||
|
{ Now get disk / by AddDisk. DiskFree and DiskSize below should return
|
||||||
|
the same (well, assuming that nothing was writeen to disk between
|
||||||
|
calls...). }
|
||||||
|
{$ifdef unix}
|
||||||
|
DiskNum := AddDisk('/');
|
||||||
|
{$else}
|
||||||
|
{ dos/windows/os/2 ... Still needs other cases for other OSes }
|
||||||
|
DiskNum := AddDisk('C:');
|
||||||
|
{$endif}
|
||||||
|
Writeln(DiskFree(DiskNum), '/', DiskSize(DiskNum));
|
||||||
|
if (disksize(3)<>disksize(disknum)) then
|
||||||
|
halt(1);
|
||||||
|
end.
|
25
tests/webtbs/tw9985a.pp
Normal file
25
tests/webtbs/tw9985a.pp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{ %opt=-gh }
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
|
||||||
|
uses Dos;
|
||||||
|
|
||||||
|
var
|
||||||
|
DiskNum: Byte;
|
||||||
|
begin
|
||||||
|
HaltOnNotReleased := true;
|
||||||
|
Writeln(DiskFree(3), '/', DiskSize(3));
|
||||||
|
|
||||||
|
{ Now get disk / by AddDisk. DiskFree and DiskSize below should return
|
||||||
|
the same (well, assuming that nothing was writeen to disk between
|
||||||
|
calls...). }
|
||||||
|
{$ifdef unix}
|
||||||
|
DiskNum := AddDisk('/');
|
||||||
|
{$else}
|
||||||
|
{ dos/windows/os/2 ... Still needs other cases for other OSes }
|
||||||
|
DiskNum := AddDisk('C:');
|
||||||
|
{$endif}
|
||||||
|
Writeln(DiskFree(DiskNum), '/', DiskSize(DiskNum));
|
||||||
|
if (disksize(3)<>disksize(disknum)) then
|
||||||
|
halt(1);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user