Tcl Source Code

View Ticket
Login
Ticket UUID: 1083082
Title: Memory leak at startup
Type: Bug Version: obsolete: 8.5a2
Submitter: pointsman Created on: 2004-12-10 18:15:48
Subsystem: 38. Init - Library - Autoload Assigned To: dgp
Priority: 8 Severity:
Status: Closed Last Modified: 2004-12-14 05:12:00
Resolution: Fixed Closed By: dgp
    Closed on: 2004-12-13 22:12:00
Description:
tcl head 10 dec 2004, compiled with --enable-symbols,
-DPURIFY.

Script is only:

proc exit args {}

valgrind reports:

==18300== ERROR SUMMARY: 0 errors from 0 contexts
(suppressed: 27 from 2)
==18300== malloc/free: in use at exit: 12742 bytes in
264 blocks.
==18300== malloc/free: 6005 allocs, 5741 frees, 394569
bytes allocated.
==18300== For counts of detected errors, rerun with: -v
==18300== searching for pointers to 264 not-freed blocks.
==18300== checked 4668828 bytes.
==18300== 
==18300== 120 bytes in 5 blocks are definitely lost in
loss record 2 of 3
==18300==    at 0x40027B98: malloc
(vg_replace_malloc.c:153)
==18300==    by 0x40251A1D: TclpAlloc
(../generic/tclAlloc.c:685)
==18300==    by 0x402592E5: Tcl_Alloc
(../generic/tclCkalloc.c:1018)
==18300==    by 0x402DBD38: Tcl_NewStringObj
(../generic/tclStringObj.c:211)
==18300==    by 0x402E6C9E: TclGetProcessGlobalValue
(../generic/tclUtil.c:2798)
==18300==    by 0x4028801B: TclGetLibraryPath
(../generic/tclEncoding.c:325)
==18300==    by 0x4028B242:
InitializeEncodingSearchPath (../generic/tclEncoding
.c:3074)
==18300==    by 0x402E6C72: TclGetProcessGlobalValue
(../generic/tclUtil.c:2790)
==18300==    by 0x40287F91: TclGetEncodingSearchPath
(../generic/tclEncoding.c:2
81)
==18300==    by 0x4028808C: MakeFileMap
(../generic/tclEncoding.c:385)
==18300==    by 0x4028B3B8: InitializeEncodingFileMap
(../generic/tclEncoding.c:
3129)
==18300==    by 0x402E6C72: TclGetProcessGlobalValue
(../generic/tclUtil.c:2790)
==18300==    by 0x40288E8F: LoadEncodingFile
(../generic/tclEncoding.c:1344)
==18300==    by 0x4028857B: Tcl_GetEncoding
(../generic/tclEncoding.c:669)
==18300==    by 0x402F4811:
TclpGetEncodingNameFromEnvironment (tclUnixInit.c:61
5)
==18300==    by 0x402F4752: TclpSetInitialEncodings
(tclUnixInit.c:581)
==18300==    by 0x40288E31: Tcl_FindExecutable
(../generic/tclEncoding.c:1305)
==18300==    by 0x402BBC12: Tcl_Main
(../generic/tclMain.c:339)
==18300==    by 0x8048705: main (tclAppInit.c:87)
==18300==    by 0x4035D8AD: __libc_start_main (in
/lib/libc.so.6)
==18300== 
==18300== LEAK SUMMARY:
==18300==    definitely lost: 120 bytes in 5 blocks.
==18300==    possibly lost:   0 bytes in 0 blocks.
==18300==    still reachable: 12622 bytes in 259 blocks.
==18300==         suppressed: 0 bytes in 0 blocks.
==18300== Reachable blocks (those to which a pointer
was found) are not shown.
==18300== To see them, rerun with: --show-reachable=yes
==18300==
User Comments: dgp added on 2004-12-14 05:12:00:
Logged In: YES 
user_id=80530

fixed in HEAD for 8.5a3

pointsman added on 2004-12-14 04:23:55:
Logged In: YES 
user_id=13222

Hey! Now, at least for the given very simple test script
with only the exit trick from above, tcl cleans up *all*
memory after itself.

That's what valgrind say:

 ==24057== ERROR SUMMARY: 0 errors from 0 contexts
(suppressed: 26 from 2)
==24057== malloc/free: in use at exit: 0 bytes in 0 blocks.
==24057== malloc/free: 5954 allocs, 5954 frees, 393712 bytes
allocated.
==24057== For counts of detected errors, rerun with: -v
==24057== No malloc'd blocks -- no leaks are possible.

Great!

dgp added on 2004-12-14 02:15:21:

File Deleted - 112020: 



File Added - 112328: 1083082.patch

Logged In: YES 
user_id=80530


another patch update.  please test again.

pointsman added on 2004-12-11 09:36:15:
Logged In: YES 
user_id=13222

Fixed now. Valgrind doesn't report any 'definitely lost'
memory any more. With the 'exit trick' from 
http://mini.net/tcl/3248, even the 'still reachable' are
almost back to the low numbers of the late 8.4.x releases.
I'm aware, that they are another topic and no real harm, but
only noise. They are currently:

==27065== ERROR SUMMARY: 0 errors from 0 contexts
(suppressed: 27 from 2)
==27065== malloc/free: in use at exit: 132 bytes in 4 blocks.
==27065== malloc/free: 5979 allocs, 5975 frees, 393983 bytes
allocated.
==27065== For counts of detected errors, rerun with: -v
==27065== searching for pointers to 4 not-freed blocks.
==27065== checked 4660992 bytes.
==27065== 
==27065== 40 bytes in 1 blocks are still reachable in loss
record 1 of 2
==27065==    at 0x4002811A: realloc (vg_replace_malloc.c:310)
==27065==    by 0x40251A6C: TclpRealloc
(../generic/tclAlloc.c:733)
==27065==    by 0x402593F0: Tcl_Realloc
(../generic/tclCkalloc.c:1101)
==27065==    by 0x402DC514: Tcl_SetObjLength
(../generic/tclStringObj.c:777)
==27065==    by 0x4029C869: TclpNativeJoinPath
(../generic/tclFileName.c:764)
==27065==    by 0x402CE485: Tcl_FSJoinPath
(../generic/tclPathObj.c:993)
==27065==    by 0x4029C764: Tcl_FSJoinToPath
(../generic/tclFileName.c:689)
==27065==    by 0x4028B3CC: InitializeEncodingSearchPath
(../generic/tclEncoding.c:3083)
==27065==    by 0x402E6E04: TclGetProcessGlobalValue
(../generic/tclUtil.c:2791)
==27065==    by 0x402880B1: TclGetEncodingSearchPath
(../generic/tclEncoding.c:281)
==27065==    by 0x402881AC: MakeFileMap
(../generic/tclEncoding.c:385)
==27065==    by 0x4028B4F0: InitializeEncodingFileMap
(../generic/tclEncoding.c:3130)
==27065==    by 0x402E6E04: TclGetProcessGlobalValue
(../generic/tclUtil.c:2791)
==27065==    by 0x40288FAF: LoadEncodingFile
(../generic/tclEncoding.c:1344)
==27065==    by 0x4028869B: Tcl_GetEncoding
(../generic/tclEncoding.c:669)
==27065==    by 0x402F49A5:
TclpGetEncodingNameFromEnvironment (tclUnixInit.c:615)
==27065==    by 0x402F48E6: TclpSetInitialEncodings
(tclUnixInit.c:581)
==27065==    by 0x40288F51: Tcl_FindExecutable
(../generic/tclEncoding.c:1305)
==27065==    by 0x402BBD4A: Tcl_Main (../generic/tclMain.c:339)
==27065==    by 0x8048705: main (tclAppInit.c:87)
==27065== 
==27065== 
==27065== 92 bytes in 3 blocks are still reachable in loss
record 2 of 2
==27065==    at 0x40027B98: malloc (vg_replace_malloc.c:153)
==27065==    by 0x40251A1D: TclpAlloc
(../generic/tclAlloc.c:685)
==27065==    by 0x402592E5: Tcl_Alloc
(../generic/tclCkalloc.c:1018)
==27065==    by 0x402DBEBC: Tcl_NewStringObj
(../generic/tclStringObj.c:211)
==27065==    by 0x402CE218: Tcl_FSJoinPath
(../generic/tclPathObj.c:910)
==27065==    by 0x4029C764: Tcl_FSJoinToPath
(../generic/tclFileName.c:689)
==27065==    by 0x4028B3CC: InitializeEncodingSearchPath
(../generic/tclEncoding.c:3083)
==27065==    by 0x402E6E04: TclGetProcessGlobalValue
(../generic/tclUtil.c:2791)
==27065==    by 0x402880B1: TclGetEncodingSearchPath
(../generic/tclEncoding.c:281)
==27065==    by 0x402881AC: MakeFileMap
(../generic/tclEncoding.c:385)
==27065==    by 0x4028B4F0: InitializeEncodingFileMap
(../generic/tclEncoding.c:3130)
==27065==    by 0x402E6E04: TclGetProcessGlobalValue
(../generic/tclUtil.c:2791)
==27065==    by 0x40288FAF: LoadEncodingFile
(../generic/tclEncoding.c:1344)
==27065==    by 0x4028869B: Tcl_GetEncoding
(../generic/tclEncoding.c:669)
==27065==    by 0x402F49A5:
TclpGetEncodingNameFromEnvironment (tclUnixInit.c:615)
==27065==    by 0x402F48E6: TclpSetInitialEncodings
(tclUnixInit.c:581)
==27065==    by 0x40288F51: Tcl_FindExecutable
(../generic/tclEncoding.c:1305)
==27065==    by 0x402BBD4A: Tcl_Main (../generic/tclMain.c:339)
==27065==    by 0x8048705: main (tclAppInit.c:87)
==27065==    by 0x4035D8AD: __libc_start_main (in
/lib/libc.so.6)
==27065== 
==27065== LEAK SUMMARY:
==27065==    definitely lost: 0 bytes in 0 blocks.
==27065==    possibly lost:   0 bytes in 0 blocks.
==27065==    still reachable: 132 bytes in 4 blocks.
==27065==         suppressed: 0 bytes in 0 blocks.
==27065==

dgp added on 2004-12-11 05:18:41:
Logged In: YES 
user_id=80530

please test and report when you
get a chance.

dgp added on 2004-12-11 02:57:27:

File Deleted - 112015: 



File Added - 112020: 1083082.patch

Logged In: YES 
user_id=80530

updated patch should correct that too.

pointsman added on 2004-12-11 02:35:53:
Logged In: YES 
user_id=13222

Tested with the patch. Looks like sill not clean. 

Now valgrind reports:

==22390== ERROR SUMMARY: 0 errors from 0 contexts
(suppressed: 27 from 2)
==22390== malloc/free: in use at exit: 272 bytes in 10 blocks.
==22390== malloc/free: 5979 allocs, 5969 frees, 393962 bytes
allocated.
==22390== For counts of detected errors, rerun with: -v
==22390== searching for pointers to 10 not-freed blocks.
==22390== checked 4661072 bytes.
==22390== 
==22390== 48 bytes in 2 blocks are definitely lost in loss
record 1 of 3
==22390==    at 0x40027B98: malloc (vg_replace_malloc.c:153)
==22390==    by 0x40251A1D: TclpAlloc
(../generic/tclAlloc.c:685)
==22390==    by 0x402592E5: Tcl_Alloc
(../generic/tclCkalloc.c:1018)
==22390==    by 0x402DBD38: Tcl_NewStringObj
(../generic/tclStringObj.c:211)
==22390==    by 0x40288E6E: LoadEncodingFile
(../generic/tclEncoding.c:1338)
==22390==    by 0x4028857B: Tcl_GetEncoding
(../generic/tclEncoding.c:669)
==22390==    by 0x4028884B: Tcl_SetSystemEncoding
(../generic/tclEncoding.c:870)
==22390==    by 0x402F476D: TclpSetInitialEncodings
(tclUnixInit.c:581)
==22390==    by 0x40288E31: Tcl_FindExecutable
(../generic/tclEncoding.c:1305)
==22390==    by 0x402BBC12: Tcl_Main (../generic/tclMain.c:339)
==22390==    by 0x8048705: main (tclAppInit.c:87)
==22390==    by 0x4035D8AD: __libc_start_main (in
/lib/libc.so.6)
==22390==    by 0x8048630: (within
/usr/local/tcl-head/bin/tclsh8.5)
==22390== 
==22390== LEAK SUMMARY:
==22390==    definitely lost: 48 bytes in 2 blocks.
==22390==    possibly lost:   0 bytes in 0 blocks.
==22390==    still reachable: 224 bytes in 8 blocks.
==22390==         suppressed: 0 bytes in 0 blocks.

dgp added on 2004-12-11 02:22:37:

File Added - 112015: 1083082.patch

Logged In: YES 
user_id=80530

please test this patch.

dgp added on 2004-12-11 02:17:38:
Logged In: YES 
user_id=80530


Thanks for the report.

Looks like FreeThreadHash
is missing a ClearHash call...

Attachments: