Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some memory leak issue with InstanceHandle #3493

Merged
merged 6 commits into from
Jan 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/vm/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,19 @@ pub struct InstanceHandle {
instance: NonNull<Instance>,
}

/// InstanceHandle are created with an InstanceAllocator
/// and it will "consume" the memory
/// So the Drop here actualy free it (else it would be leaked)
impl Drop for InstanceHandle {
fn drop(&mut self) {
let instance_ptr = self.instance.as_ptr();

unsafe {
std::alloc::dealloc(instance_ptr as *mut u8, self.instance_layout);
}
}
}

impl InstanceHandle {
/// Create a new `InstanceHandle` pointing at a new [`InstanceRef`].
///
Expand Down