Skip to content

crash using by-value records with mutable fields #2493

Closed
@nikomatsakis

Description

@nikomatsakis

The following program will segfault, double free, leak, and generally misbehave:

type T = {mut f: @int};
fn foo(++x: T) { x.f = @4; }
fn main() {
    let x = {mut f: @3};
    foo(x);
}

The reason is our by-value protocol: we copy the data for the record but do not invoke the take-glue (nor drop-glue). As a result, the assignment x.f = @4 within foo() causes the original @3 to be freed, but never arranges for the new @4 to be released. When foo() returns, main() tries to drop its copy of x, which still contains the original @3 pointer.

Of course the same badness would happen if the type T included a unique pointer. Or really anything that requires take/drop-glue.

Metadata

Metadata

Assignees

Labels

A-codegenArea: Code generationI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions