Skip to content
Tcl Source Code View Ticket
Login

View Ticket

dgp-refactor TclStackFree panic

Closed / Fixed8c52e7873850438e512afa106284e299812dc48dCreated 3 years agoUpdated 3 years ago
Descriptionplain2023-07-21 16:00:54
The dgp-refactor branch has been exhibiting a panic in TclStackFree
since the merge of TIP 636 from trunk.  Some merge flaw has introduced
a defect.

Here is a stripped down demo of the panic:

proc demo {} {
    set l {}
    namespace eval {} {}
    lappend l a b
}
demo

TclStackFree: incorrect freePtr (0x2489b50 != 0x2489b3f). Call out of sequence?


The [set] and [lappend] commands have the effect of getting "l"
treated as a compiled local variable.  The panicking TclStackFree
is one that releases a compiled local previously created with
TclStackAlloc.  The [namespace eval] seems to be where the corruption
happens, and the most likely suspect is in the invokeReplace instruction.

Note also that the reported mismatch reports a value of
MEMSTART(markerPtr) ending in f, which doesn't seem to be
a result with an acceptable alignment, which is supposed to
be part of what MEMSTART() does.  Very strange symptoms.
dgpplain2023-08-03 19:15:25
Don't understand it yet, but the cause is a call to

TclDuplicatePureObj()

in the implementation of the INST_LAPPEND_* instructions.

Replace that with the old standby Tcl_DuplicateObj() and
the panics are gone.
dgpplain2023-08-03 19:45:52
TclDuplicatePureObj() includes a call to Tcl_ConvertToType()

When the type is "bytecode", the conversion steps can stomp on
the execution stack hanging off the interp.

This is a general problem with the bytecode execution engine
whenever it calls any function that takes an "interp" argument
that might somehow circle back into the execution stack.  Any
routine like this needs protecting with enclosure in

DECACHE_STACK_INFO()
...
CACHE_STACK_INFO()

I don't know why the panic only showed up on the dgp-refactor branch,
but it seems to me the argument for protecting the execution stack
would apply on trunk as well.

A search through the tickets for CACHE_STACK_INFO should turn up
more detailed background information from earlier similar problems.
This is a nasty, hard-to-debug design defect that recurs occasionally.
A more fundamental design solution would be welcome.
dgp Closed ticket [8c52e78738]. [History diff]2023-08-03 19:50:30
Log in (anonymous is fine) to add a comment.