Tcl Source Code

View Ticket
Login
Ticket UUID: 688fcc7082fa99a4bd934098c58666841e9e0b0a
Title: trace on imported alias deletes alias and then calls import and triggers memory error
Type: Bug Version:
Submitter: pooryorick Created on: 2020-08-16 09:52:56
Subsystem: - New Builtin Commands Assigned To: pooryorick
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2021-06-21 21:36:36
Resolution: Fixed Closed By: pooryorick
    Closed on: 2021-06-21 21:36:36
Description:

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.

User Comments: pooryorick added on 2021-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.


jan.nijtmans added on 2021-05-20 15:53:22:

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


jan.nijtmans added on 2021-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.


pooryorick added on 2021-05-18 14:30:25:

Fixed again in [3b0e92b198b86975].


jan.nijtmans added on 2021-05-18 08:47:19:

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


pooryorick added on 2021-05-17 21:35:32:

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


pooryorick added on 2020-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.