Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-09-21
09:30 • Closed ticket [c7d0bc9a54]: Newly introduced unshared (local-only) literals from... artifact: f7bcc5e0a6 user: jan.nijtmans
09:08 • Ticket [c7d0bc9a54]: 3 changes artifact: 737509a1d5 user: gustafn2
2016-09-16
09:09 • Ticket [c7d0bc9a54]: 4 changes artifact: 383b9e2aca user: jan.nijtmans
09:06
Fix [c7d0bc9a549714e0]: Newly introduced unshared (local-only) literals from cmd resolvers cause Tcl... check-in: 8924992522 user: jan.nijtmans tags: core-8-6-branch
07:51 • Ticket [c7d0bc9a54] Newly introduced unshared (local-only) literals from cmd res... artifact: fc61efd0e4 user: gustafn2
2016-09-15
13:27 • Ticket [c7d0bc9a54]: 3 changes artifact: be1a07d8a6 user: jan.nijtmans
13:22
Proposed fix for [c7d0bc9a549714e0]. Thanks to mr_calvin closed check-in: 2dbbe15297 user: jan.nijtmans tags: bug-c7d0bc9a549714e0
10:43 • Ticket [c7d0bc9a54] Newly introduced unshared (local-only) literals from cmd res... artifact: 5ba697742f user: mr_calvin
10:42 • Add attachment unsharedLiteral.patch to ticket [c7d0bc9a549714e0|c7d0bc... artifact: 2f7cc1858e user: mr_calvin
10:41 • New ticket [c7d0bc9a54] Newly introduced unshared (local-only) literals from cmd... artifact: d39da93dea user: mr_calvin

Newly introduced unshared (local-only) literals from cmd resolvers cause Tcl_Obj leaks

Closed / Fixedc7d0bc9a549714e031971ea60e6b0392b51d0d75Created 10 years agoUpdated 10 years ago
Descriptionplain2016-09-15 10:41:54
The recently applied changes in response to http://core.tcl.tk/tcl/tktview?name=d4e7780ca1 open up a Tcl_Obj leak because refcounting was not adjusted accordingly, e.g.:

==28916== 93 (48 direct, 45 indirect) bytes in 1 blocks are definitely lost in loss record 35 of 64
==28916==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==28916==    by 0x50ED4F2: TclpAlloc (tclAlloc.c:699)
==28916==    by 0x5104DDC: Tcl_Alloc (tclCkalloc.c:1059)
==28916==    by 0x521525E: TclCreateLiteral (tclLiteral.c:236)
==28916==    by 0x52155F9: TclRegisterLiteral (tclLiteral.c:445)
==28916==    by 0x51A0F99: CompileCmdLiteral (tclCompile.c:1794)
==28916==    by 0x51A1242: TclCompileInvocation (tclCompile.c:1814)
==28916==    by 0x51A252B: CompileCommandTokens (tclCompile.c:2074)
==28916==    by 0x51A2940: TclCompileScript (tclCompile.c:2193)
==28916==    by 0x51A3BE6: TclCompileTokens (tclCompile.c:2442)
==28916==    by 0x5157AFC: TclCompileNamespaceTailCmd (tclCompCmdsGR.c:2055)
==28916==    by 0x51C2F67: TclAttemptCompileProc (tclEnsemble.c:3212)

The literal Tcl_Obj kept being bumped to reflect a global literal reference unconditionally, i.e., even when it is treated as unshared, local-only literal in subsequent steps. The fix is to move Tcl_IncrRefCount(objPtr) further down in TclCreateLiteral(), when it becomes certain that the literal actually becomes global.
I would also suggest adjusting the in-code comments slightly, to better reflect the modified literal handling.

See attached path for both.
mr_calvinplain2016-09-15 10:43:24
Assigned to Jan, because he also sponsored the original patch.
jan.nijtmanswiki2016-09-15 13:27:56

Proposed fix committed to branch bug-c7d0bc9a549714e0. Appears fully valid to me. Asking feedback from Gustaf Neumann.

gustafn2plain2016-09-16 07:51:08
The fix is correct. i did some larger tests (naviserver, valgrind, ...) everything looks ok.
jan.nijtmansplain2016-09-16 09:09:50
Fix committed to core-8-6-branch and trunk. In-code oomments not taken into account yet, I'll leave that in the hands of Gustaf. Therefore keeping this ticket open for the moment.
gustafn2plain2016-09-21 09:08:06
The modified inline comments reflect the differentiation between global (shared) and unshared literals properly.
jan.nijtmansplain2016-09-21 09:30:54
Better inline comment handled by "trunk" now. Closing
Log in (anonymous is fine) to add a comment.