Skip to content

Failure in a destructor leaks the entire task #16437

@sfackler

Description

@sfackler

I was under the impression that failure in a a destructor will leak that object, but not the entire task.

"dropped" doesn't print here:

struct Dropper {
    v: Vec<u8>,
}

impl Drop for Dropper {
    fn drop(&mut self) {
        println!("dropping");
    }
}

struct Failer;

impl Drop for Failer {
    fn drop(&mut self) {
        fail!();
    }
}

fn main() {
    let _d = Dropper { v: Vec::with_capacity(10000) };
    Failer;
}
==6462== Memcheck, a memory error detector
==6462== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==6462== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==6462== Command: ./test
==6462== 
task '<main>' failed at 'explicit failure', test.rs:15
==6462== 
==6462== HEAP SUMMARY:
==6462==     in use at exit: 12,288 bytes in 1 blocks
==6462==   total heap usage: 14 allocs, 13 frees, 13,000 bytes allocated
==6462== 
==6462== LEAK SUMMARY:
==6462==    definitely lost: 12,288 bytes in 1 blocks
==6462==    indirectly lost: 0 bytes in 0 blocks
==6462==      possibly lost: 0 bytes in 0 blocks
==6462==    still reachable: 0 bytes in 0 blocks
==6462==         suppressed: 0 bytes in 0 blocks
==6462== Rerun with --leak-check=full to see details of leaked memory
==6462== 
==6462== For counts of detected and suppressed errors, rerun with: -v
==6462== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1 from 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions