Skip to content

Drop finalizer on newtype structs does not work #6090

Closed
@brson

Description

@brson

This will leak the ptr. Valgrind will complain.

use core::libc::{c_void, malloc, free};

struct SmartPtr(*c_void);

impl Drop for SmartPtr {
    fn finalize(&self) {
        unsafe {
            error!("end ptr: %x", **self as uint);
            free(**self);
        }
    }
}

fn main() {
    unsafe {
        let junk = malloc(4);
        error!("start ptr: %x", junk as uint);
        let _junkbox = SmartPtr(junk);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions