Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-17
08:23 • Ticket [0ef291c1c2] memory corruption with trace + transchan status still Op... artifact: 2df1e85b8c user: serhiy.storchaka
08:21
Fix [0ef291c1c2]: memory corruption with trace + transchan. InvokeTclMethod() used the command words... check-in: 9c18d04ed6 user: serhiy.storchaka tags: iortrans-reentrant-argv
2016-10-08
16:58 • Ticket [0ef291c1c2] memory corruption with trace + transchan status still Op... artifact: ad369d5a2e user: dkf
2016-09-20
21:21 • Ticket [0ef291c1c2]: 3 changes artifact: 8e2b653021 user: ferrieux
14:20 • Ticket [0ef291c1c2]: 3 changes artifact: 34cd4946c9 user: aspect
14:13 • Add attachment oops-tcl-panic.bt to ticket [0ef291c1c287e325|0ef291c1c2... artifact: 04189ddfe8 user: aspect
12:42 • Ticket [0ef291c1c2] memory corruption with trace + transchan status still Op... artifact: 27a738820e user: ferrieux
10:33 • Add attachment oops.valgrind to ticket [0ef291c1c2] artifact: 796a2088ae user: aspect
10:32 • Add attachment oops.memtrace to ticket [0ef291c1c2] artifact: ee4f11916a user: aspect
10:32 • Add attachment oops.bt to ticket [0ef291c1c2] artifact: 956132c6fd user: aspect
10:32 • New ticket [0ef291c1c2] memory corruption with trace + transchan. artifact: 2a396eeaeb user: aspect

memory corruption with trace + transchan

Open0ef291c1c287e325a8e5d17c1390e5a733c12fc9Created 10 years agoUpdated 47 days ago
Descriptionplain2016-09-20 10:32:03
Test script:
~~~
proc trans args {list initialize finalize write}
chan push stdout trans#11 0x00007ffff7b162d0 in Tcl_PopCallFrame (interp=0x6305b0) at /home/aspect/Tcl/Env/src/tcl/generic/tclNamesp.c:404

proc trans args {list}  ;# optional - cleans up output

proc foo {} {puts okay}
trace add execution foo enterstep {puts X; list}
foo
~~~

aborts with:
~~~
file = /home/aspect/Tcl/Env/src/tcl/generic/tclListObj.c, line = 124
incrementing refCount of previously disposed object
~~~

valgrind, memtrace, gdb backtrace attached.
Referenced by1
  • 9c18d04ed6Fix [0ef291c1c2]: memory corruption with trace + transchan. InvokeTclMethod() used the command words preallocated per transform, so a handler which re-entered the same transform overwrote and freed the words of the outer call. Copy them for each call. check-in2026-10-17 08:21:17
ferrieuxplain2016-09-20 12:42:26
Unless I'm mistaken, the gdb bt ends in a different panic:
"invalid block: 0x7ffff7a0d9af: 2d ff"

Does it mean there is an heisenbug touch to it ?
Or that when compiling with -g, the behavior differs ?
aspectplain2016-09-20 14:20:27
> Or that when compiling with -g, the behavior differs ?

Different compile options make it manifest differently - looks like
memory corruption.  My guess is refcount management, though whether
in trace or transchan machinery or somewhere else I have no idea.
[puts] in both locations seems to be required.

oops.bt is --enable-symbols=yes, the others (and now
oops-tcl-panic.bt) are with --enable-symbols=all.

The stack traces start the same but diverge above TclNRRunCallbacks
at #13/#11 .. maybe that's helpful.
ferrieuxplain2016-09-20 21:21:29
Thanks, it's much better to chase a single goose at a time.
With the proper configure flags I reproduced locally, and with a hardware watchpoint on the (constant) offending "previously disposed object", it appears the last overwrite is a bulk erasure within Tcl_DeleteHashEntry, *not* an individual object-freeing.

So, as you suggest, something very wrong might have happened some time ago, ending up in InitArgsAndLocals passing a bunch of stale pointers to NewList.

Need more digging...
dkf Ticket [0ef291c1c2]: 3 changes [History diff]2016-10-08 16:58:40
serhiy.storchakawiki2026-10-17 08:23:03

Reproduced on main and 8.6 (heap-use-after-free under ASan; 9.0 has the same code): InvokeTclMethod() in tclIORTrans.c fills the command words preallocated for the transform, so when the handler re-enters the same transform (here the trace's [puts]), the nested call overwrites and frees the words of the outer call that is still running. Proposed fix in branch iortrans-reentrant-argv: copy the words for each call. Test iortrans-bug-0ef291c1c2.

Log in (anonymous is fine) to add a comment.

Attachments: