-
Notifications
You must be signed in to change notification settings - Fork 761
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
fix: memory leak in unsafe code #12446
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's merge
return Some(std::ptr::read(raw_ptr as *const Self)); | ||
let raw_ptr = Box::into_raw(boxed) as *mut dyn BlockMetaInfo; | ||
let typed_ptr = raw_ptr as *mut Self; | ||
return Some(*Box::from_raw(typed_ptr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'll be more consice if we write:
let downcast_box = std::mem::transmute::<Box<_>, Box<Self>>(boxed);
*downcast_box
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! BTW, I want to discuss, what about removing unsafe code by writing somthing like boxed.into_any().downcast()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it may be not able to take ownership from Box<Any>
, but we can clone it anyway.
* fix: memory leak in unsafe code * respect gpt advice
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Summary about this PR
This change is