trace on imported alias deletes alias and then calls import and triggers memory error
-DPURIFY and --enable-symbols, the
following script results in a segmentation fault:
variable res {}
namespace eval ns1 {
namespace export *
proc p1 {} {
return success
}
interp alias {} [namespace current]::p2 {} [namespace current]::p1
}
namespace eval ns2 {
namespace import [namespace parent]::ns1::p2
}
proc ondelete {oldname newname op} {
variable res
catch {
$oldname
} cres
set res [string match {invalid command name*ns1::p1*} $cres]
}
trace add command ns2::p2 delete ondelete
namespace delete ns1
The issue is that the delete trace on the imported routine deletes the
namespace of the underlying routine, resulting in the deletion of both the
underlying routine and the alias, but then the imported command is called, and
its ImportedCmdData structure still holds a reference to the
now-deleted Alias structure.
113ceaa417Merge 8.6, except [688fcc7082] because it gives a merge conflict check-in2021-05-20 12:35:19
Fixed in [037c0ff27fd5d0a2] by modifying
Tcl_DeleteCommandFromToken() so that it deletes any imports of the
routine before deleting the routine itself.
Fix applied to core-8-6-branch in [e45d054ba46ee5c2].
Re-opening, because this fix broke the build: https://github.com/tcltk/tcl/actions/runs/852459210
Fixed again in [3b0e92b198b86975].
This - indeed - looks OK now, but it's only applied to 8.6 yet. Will 8.7 and 9.0 follow soon? Then it can be closed.
@pooryorick: Noting that commit [3b0e92b198b86975] was on core-8-branch, is this bug now fixed on all branches?
This fix was committed to core-8-branch in [037c0ff27fd5d0a2] and also made its way to trunk via merge of core-8-branch. [3b0e92b198b86975] is unrelated and shouldn't have been noted in this report.