From 176a63b67b0e570857505b6b3b97caf558e8dbdd Mon Sep 17 00:00:00 2001 From: svenbarth Date: Fri, 19 Jul 2019 15:55:21 +0000 Subject: [PATCH] * fix for Mantis #35862: free the list of functions added with AddTerminateProc to avoid memory leaks + added test git-svn-id: trunk@42457 - --- .gitattributes | 1 + rtl/amicommon/sysutils.pp | 1 + rtl/atari/sysutils.pp | 1 + rtl/embedded/sysutils.pp | 1 + rtl/emx/sysutils.pp | 1 + rtl/gba/sysutils.pp | 1 + rtl/go32v2/sysutils.pp | 1 + rtl/macos/sysutils.pp | 1 + rtl/msdos/sysutils.pp | 1 + rtl/nativent/sysutils.pp | 1 + rtl/nds/sysutils.pp | 1 + rtl/netware/sysutils.pp | 1 + rtl/netwlibc/sysutils.pp | 1 + rtl/objpas/sysutils/sysutils.inc | 13 +++++++++++++ rtl/os2/sysutils.pp | 1 + rtl/symbian/sysutils.pp | 1 + rtl/unix/sysutils.pp | 1 + rtl/watcom/sysutils.pp | 1 + rtl/wii/sysutils.pp | 1 + rtl/win/sysutils.pp | 1 + rtl/win16/sysutils.pp | 1 + rtl/wince/sysutils.pp | 1 + tests/webtbs/tw35862.pp | 22 ++++++++++++++++++++++ 23 files changed, 56 insertions(+) create mode 100644 tests/webtbs/tw35862.pp diff --git a/.gitattributes b/.gitattributes index 08d79071c7..9e9ed0005b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16698,6 +16698,7 @@ tests/webtbs/tw3577.pp svneol=native#text/plain tests/webtbs/tw3578.pp svneol=native#text/plain tests/webtbs/tw3579.pp svneol=native#text/plain tests/webtbs/tw3583.pp svneol=native#text/plain +tests/webtbs/tw35862.pp svneol=native#text/pascal tests/webtbs/tw3589.pp svneol=native#text/plain tests/webtbs/tw3594.pp svneol=native#text/plain tests/webtbs/tw3595.pp svneol=native#text/plain diff --git a/rtl/amicommon/sysutils.pp b/rtl/amicommon/sysutils.pp index 15131a4620..9bf99e23a4 100644 --- a/rtl/amicommon/sysutils.pp +++ b/rtl/amicommon/sysutils.pp @@ -955,4 +955,5 @@ Initialization RefreshDeviceList; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/atari/sysutils.pp b/rtl/atari/sysutils.pp index 37181d5e0e..7be4308aad 100644 --- a/rtl/atari/sysutils.pp +++ b/rtl/atari/sysutils.pp @@ -533,4 +533,5 @@ Initialization Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/embedded/sysutils.pp b/rtl/embedded/sysutils.pp index ac1dbbee60..40d9f7c7f0 100644 --- a/rtl/embedded/sysutils.pp +++ b/rtl/embedded/sysutils.pp @@ -292,4 +292,5 @@ Initialization InitExceptions; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/emx/sysutils.pp b/rtl/emx/sysutils.pp index c25bf69d35..4168714eab 100644 --- a/rtl/emx/sysutils.pp +++ b/rtl/emx/sysutils.pp @@ -1341,4 +1341,5 @@ Initialization InitInternational; { Initialize internationalization settings } Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/gba/sysutils.pp b/rtl/gba/sysutils.pp index 5b76924288..43b3c85270 100644 --- a/rtl/gba/sysutils.pp +++ b/rtl/gba/sysutils.pp @@ -326,4 +326,5 @@ Initialization InitExceptions; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/go32v2/sysutils.pp b/rtl/go32v2/sysutils.pp index 083e32ec97..31eeee0384 100644 --- a/rtl/go32v2/sysutils.pp +++ b/rtl/go32v2/sysutils.pp @@ -921,4 +921,5 @@ Initialization OnBeep:=@SysBeep; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/macos/sysutils.pp b/rtl/macos/sysutils.pp index 9b4e827822..083d128bd3 100644 --- a/rtl/macos/sysutils.pp +++ b/rtl/macos/sysutils.pp @@ -850,4 +850,5 @@ Initialization InitInternational; { Initialize internationalization settings } Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/msdos/sysutils.pp b/rtl/msdos/sysutils.pp index f51377c69e..14b45ba39c 100644 --- a/rtl/msdos/sysutils.pp +++ b/rtl/msdos/sysutils.pp @@ -930,4 +930,5 @@ Initialization OnBeep:=@SysBeep; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/nativent/sysutils.pp b/rtl/nativent/sysutils.pp index daf7c02ede..f06787ffa8 100644 --- a/rtl/nativent/sysutils.pp +++ b/rtl/nativent/sysutils.pp @@ -1264,4 +1264,5 @@ initialization OnBeep := @SysBeep; finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/nds/sysutils.pp b/rtl/nds/sysutils.pp index 35cdec4e11..82ec1cd4b4 100644 --- a/rtl/nds/sysutils.pp +++ b/rtl/nds/sysutils.pp @@ -365,4 +365,5 @@ Initialization InitExceptions; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/netware/sysutils.pp b/rtl/netware/sysutils.pp index 40f6256ad0..8da7f68563 100644 --- a/rtl/netware/sysutils.pp +++ b/rtl/netware/sysutils.pp @@ -662,4 +662,5 @@ Initialization OnBeep:=@SysBeep; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/netwlibc/sysutils.pp b/rtl/netwlibc/sysutils.pp index d7e3f0bd4e..4ad7a745bc 100644 --- a/rtl/netwlibc/sysutils.pp +++ b/rtl/netwlibc/sysutils.pp @@ -729,4 +729,5 @@ Initialization InitInternational; { Initialize internationalization settings } Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/objpas/sysutils/sysutils.inc b/rtl/objpas/sysutils/sysutils.inc index aa5b8f0a06..c97422b256 100644 --- a/rtl/objpas/sysutils/sysutils.inc +++ b/rtl/objpas/sysutils/sysutils.inc @@ -653,6 +653,19 @@ begin end; end; +procedure FreeTerminateProcs; +var + TPR1, TPR2: PPRecord; +begin + TPR1 := TPList; + TPList := Nil; + while Assigned(TPR1) do begin + TPR2 := TPR1^.NextFunc; + Dispose(TPR1); + TPR1 := TPR2; + end; +end; + { --------------------------------------------------------------------- Diskh functions, OS independent. ---------------------------------------------------------------------} diff --git a/rtl/os2/sysutils.pp b/rtl/os2/sysutils.pp index 34fac97a29..1cfc041646 100644 --- a/rtl/os2/sysutils.pp +++ b/rtl/os2/sysutils.pp @@ -1004,4 +1004,5 @@ Initialization OrigOSErrorWatch := TOSErrorWatch (SetOSErrorTracking (@TrackLastOSError)); Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/symbian/sysutils.pp b/rtl/symbian/sysutils.pp index b68996e23d..eb70d11be0 100644 --- a/rtl/symbian/sysutils.pp +++ b/rtl/symbian/sysutils.pp @@ -292,4 +292,5 @@ Initialization InitExceptions; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/unix/sysutils.pp b/rtl/unix/sysutils.pp index 29d64d081f..60f2a574a7 100644 --- a/rtl/unix/sysutils.pp +++ b/rtl/unix/sysutils.pp @@ -1664,4 +1664,5 @@ Initialization Finalization FreeDriveStr; DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/watcom/sysutils.pp b/rtl/watcom/sysutils.pp index 8b6e7331ed..b44cdbf2ff 100644 --- a/rtl/watcom/sysutils.pp +++ b/rtl/watcom/sysutils.pp @@ -899,4 +899,5 @@ Initialization InitDelay; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/wii/sysutils.pp b/rtl/wii/sysutils.pp index 0a2c081d25..9bc1aecfbb 100644 --- a/rtl/wii/sysutils.pp +++ b/rtl/wii/sysutils.pp @@ -295,4 +295,5 @@ Initialization InitExceptions; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/win/sysutils.pp b/rtl/win/sysutils.pp index 8348dcc6bf..b0c4c30955 100644 --- a/rtl/win/sysutils.pp +++ b/rtl/win/sysutils.pp @@ -1659,4 +1659,5 @@ Initialization OnBeep:=@SysBeep; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/win16/sysutils.pp b/rtl/win16/sysutils.pp index 5a1948cafe..d7d4a3a9f1 100644 --- a/rtl/win16/sysutils.pp +++ b/rtl/win16/sysutils.pp @@ -952,4 +952,5 @@ Initialization OnBeep:=@SysBeep; Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/rtl/wince/sysutils.pp b/rtl/wince/sysutils.pp index c9131f73b2..dc497379d4 100644 --- a/rtl/wince/sysutils.pp +++ b/rtl/wince/sysutils.pp @@ -983,5 +983,6 @@ Initialization Finalization DoneExceptions; + FreeTerminateProcs; end. diff --git a/tests/webtbs/tw35862.pp b/tests/webtbs/tw35862.pp new file mode 100644 index 0000000000..8763349bb1 --- /dev/null +++ b/tests/webtbs/tw35862.pp @@ -0,0 +1,22 @@ +{ %OPT=-gh } + +program tw35862; + +{$modeswitch result} + +uses sysutils; + +function do_term:boolean; +begin + writeln('In terminate proc'); + Result:=true; +end; + +begin + HaltOnNotReleased:=True; + + writeln('Adding terminate proc'); + AddTerminateproc(@do_term); + writeln('terminating'); + CallterminateProcs; +end.