Tcl Source Code

View Ticket
Login
Ticket UUID: 135804138e33ff05b89f06101008113c86156322
Title: TclOO segmentation fault: direct call to a method called by the object destructor, and that deletes the object via [rename] before calling [next]
Type: Bug Version:
Submitter: pooryorick Created on: 2019-11-13 21:20:59
Subsystem: 35. TclOO Package Assigned To: sebres
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2019-11-14 19:36:01
Resolution: Fixed Closed By: pooryorick
    Closed on: 2019-11-14 19:36:01
Description:

The following script results in a segmentation fault in core-8-6-branch:

oo::class create c1 {
    method m1 {} {}
}

oo::class create c2 {
    superclass c1
    destructor {
        my m1
    }
    method m1 {} {
        rename [self] {}
        next
        # nextto c1
    }
}

c2 create obj1
obj1 m1

User Comments: sebres added on 2019-11-14 17:22:34:

Fixed now in branch bug-135804138e...

I had 2 variants to solve that.

In the 1st variant the result of test-case oo-7.10 would be something like:

- delete c2::destructor delete no-self c1::m1 unreachable /c2::destructor no-self 1 {no next method implementation}
+ delete c2::destructor delete no-self c1::m1 unreachable /c2::destructor no-self c1::m1 unreachable 0 {}
So the "next" had successfully called "c1::m1" second time, so it had assumed that only context of object is deleted (not a class in the call chain) and all access to my/self etc would be prohibited anyway, but just because "c1::m1" behaves like a proc (without object context access) it were possible without any issue to call it second time.

The interim decision was another variant (as it is currently implemented in branch bug-135804138e) is calling of "next" is impossible after object deletion - so it throws an error there.


pooryorick added on 2019-11-14 09:43:25:

The initial script is the wrong script. This is the correct script to reproduce the segmentation fault:

oo::class create c1 {
    method m1 {} {}
}

oo::class create c2 {
    superclass c1
    destructor {
        my m1
    }
    method m1 {} {
        rename [self] {}
        next
    }
}

c2 create obj1
obj1 m1


aku added on 2019-11-13 21:35:26:
I suspect that the script should be:

oo::class create c1 {
    method m1 {} {}
}

oo::class create c2 {
    superclass c1
    destructor {
        my m1
    }
    method m1 {} {
        my m2
        next
    }
    method m2 {} {
        rename [self] {}
    }
}

c2 create obj1
obj1 m1

aku added on 2019-11-13 21:32:40:
I do not see where/how `m2` is invoked.
And it seems to be an incomplete method definition as well.