* clean up heap at exit, fixes #7183

git-svn-id: trunk@4410 -
This commit is contained in:
florian 2006-08-11 22:09:29 +00:00
parent 3e054f46c3
commit d337c3ca6a
5 changed files with 54 additions and 19 deletions

View File

@ -1313,4 +1313,26 @@ begin
fillchar(internal_status,sizeof(internal_status),0);
end;
procedure FinalizeHeap;
var
poc : poschunk;
i : longint;
begin
{$ifdef HAS_SYSOSFREE}
for i:=low(freelists_free_chunk) to high(freelists_free_chunk) do
if freelists_free_chunk[i] then
SysOSFree(freelists_fixed[i]^.poc,freelists_fixed[i]^.poc^.size);
while assigned(freeoslist) do
begin
poc:=freeoslist^.next;
SysOSFree(freeoslist, freeoslist^.size);
dec(freeoslistcount);
freeoslist:=poc;
end;
{$endif HAS_SYSOSFREE}
{ release mutex }
MemoryMutexManager.MutexDone;
end;
{$endif HAS_MEMORYMANAGER}

View File

@ -663,10 +663,12 @@ end;
*****************************************************************************}
Procedure system_exit;forward;
Procedure FinalizeHeap;forward;
Procedure InternalExit;
var
current_exit : Procedure;
i : longint;
Begin
while exitProc<>nil Do
Begin
@ -691,6 +693,12 @@ Begin
Flush(ErrOutput);
Flush(StdOut);
Flush(StdErr);
{ finally release the heap if possible, especially
important for DLLs }
for i:=0 to argc do
sysfreemem(argv[i]);
sysfreemem(argv);
FinalizeHeap;
End;

View File

@ -377,7 +377,11 @@ begin
begin
Close(stderr);
Close(stdout);
Close(erroutput);
Close(Input);
Close(Output);
{ what about Input and Output ?? PM }
{ now handled, FPK }
end;
remove_exception_handlers;
@ -466,7 +470,7 @@ var
end;
DLL_THREAD_ATTACH :
begin
inc(Thread_count);
inclocked(Thread_count);
{$warning Allocate Threadvars !}
if assigned(Dll_Thread_Attach_Hook) then
Dll_Thread_Attach_Hook(DllParam);
@ -474,7 +478,7 @@ var
end;
DLL_THREAD_DETACH :
begin
dec(Thread_count);
declocked(Thread_count);
if assigned(Dll_Thread_Detach_Hook) then
Dll_Thread_Detach_Hook(DllParam);
{$warning Release Threadvars !}
@ -484,9 +488,7 @@ var
begin
Dll_entry:=true; { return value is ignored }
If SetJmp(DLLBuf) = 0 then
begin
FPC_DO_EXIT;
end;
FPC_Do_Exit;
if assigned(Dll_Process_Detach_Hook) then
Dll_Process_Detach_Hook(DllParam);
end;
@ -1237,5 +1239,5 @@ begin
errno:=0;
initvariantmanager;
initwidestringmanager;
InitWin32Widestrings
InitWin32Widestrings;
end.

View File

@ -458,7 +458,7 @@ var
end;
DLL_THREAD_ATTACH :
begin
inc(Thread_count);
inclocked(Thread_count);
{$warning Allocate Threadvars !}
if assigned(Dll_Thread_Attach_Hook) then
Dll_Thread_Attach_Hook(DllParam);
@ -466,7 +466,7 @@ var
end;
DLL_THREAD_DETACH :
begin
dec(Thread_count);
declocked(Thread_count);
if assigned(Dll_Thread_Detach_Hook) then
Dll_Thread_Detach_Hook(DllParam);
{$warning Release Threadvars !}

View File

@ -220,17 +220,17 @@ end;
{$ifdef CPUARM}
{$define FPC_SYSTEM_HAS_INT}
function floor(d : double) : double;
function floor(d : double) : double;
cdecl;external 'coredll' name 'floor';
function ceil(d : double) : double;
function ceil(d : double) : double;
cdecl;external 'coredll' name 'ceil';
function fpc_int_real(d: ValReal): ValReal;compilerproc;
begin
if d > 0 then
fpc_int_real:=floor(d)
else
else
fpc_int_real:=ceil(d);
end;
@ -564,7 +564,7 @@ var
Fargc: longint;
Fargv: ppchar;
FCmdLine: PChar;
procedure setup_arguments;
var
arglen,
@ -814,10 +814,13 @@ begin
if IsLibrary then
exit;
// ExitDLL(ExitCode);
if not IsConsole then begin
Close(stderr);
Close(stdout);
{ what about Input and Output ?? PM }
if not IsConsole then
begin
Close(stderr);
Close(stdout);
Close(erroutput);
Close(Input);
Close(Output);
end;
ExitThread(exitcode);
end;
@ -859,21 +862,21 @@ begin
end;
DLL_THREAD_ATTACH :
begin
inc(Thread_count);
inclocked(Thread_count);
{$warning Allocate Threadvars !}
if assigned(Dll_Thread_Attach_Hook) then
Dll_Thread_Attach_Hook(DllParam);
end;
DLL_THREAD_DETACH :
begin
dec(Thread_count);
declocked(Thread_count);
if assigned(Dll_Thread_Detach_Hook) then
Dll_Thread_Detach_Hook(DllParam);
{$warning Release Threadvars !}
end;
DLL_PROCESS_DETACH :
begin
FPC_DO_EXIT;
FPC_Do_Exit;
if assigned(Dll_Process_Detach_Hook) then
Dll_Process_Detach_Hook(DllParam);
end;