Borrowed pointers in destructors enable use-after-free crashes #3167
Labels
A-destructors
Area: Destructors (`Drop`, …)
A-lifetimes
Area: Lifetimes / regions
I-crash
Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
This struct has a borrowed pointer to another one of itself. By making it mutable, I can build a cycle, and then no matter the order that the destructors run, the second one will segfault because the first one's id will have been freed.
This is sort of related to #3164, and more closely related to #3039.
Probably accessing mutable &-pointers in destructors should be unsafe. If they are immutable, it should be impossible to build a cycle.
The text was updated successfully, but these errors were encountered: