Skip to content
Tcl Source Code View Ticket
Login

View Ticket

trace on imported alias deletes alias and then calls import and triggers memory error

Closed / Fixed688fcc7082fa99a4bd934098c58666841e9e0b0aCreated 6 years agoUpdated 5 years ago
Descriptionwiki2020-08-16 09:52:56
In Tcl built with -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.

Referenced by1
pooryorickwiki2020-08-16 10:06:37

Fixed in [037c0ff27fd5d0a2] by modifying Tcl_DeleteCommandFromToken() so that it deletes any imports of the routine before deleting the routine itself.

pooryorick Ticket [688fcc7082]: 3 changes [History diff]2020-08-17 10:21:42
pooryorick Closed ticket [688fcc7082]. [History diff]2020-08-29 09:03:37
pooryorickwiki2021-05-17 21:35:32

Fix applied to core-8-6-branch in [e45d054ba46ee5c2].

jan.nijtmanswiki2021-05-18 08:47:19

Re-opening, because this fix broke the build: https://github.com/tcltk/tcl/actions/runs/852459210

pooryorickwiki2021-05-18 14:30:25

Fixed again in [3b0e92b198b86975].

jan.nijtmanswiki2021-05-18 15:10:26

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.

jan.nijtmanswiki2021-05-20 15:53:22

@pooryorick: Noting that commit [3b0e92b198b86975] was on core-8-branch, is this bug now fixed on all branches?

pooryorickwiki2021-06-21 21:36:11

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.

pooryorick Closed ticket [688fcc7082]. [History diff]2021-06-21 21:36:36
Log in (anonymous is fine) to add a comment.