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

fix: memory leak in unsafe code #12446

Merged
merged 2 commits into from
Aug 12, 2023
Merged

Conversation

SkyFan2002
Copy link
Member

@SkyFan2002 SkyFan2002 commented Aug 12, 2023

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 Reviewable

@vercel
Copy link

vercel bot commented Aug 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
databend ⬜️ Ignored (Inspect) Visit Preview Aug 12, 2023 9:44am

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Aug 12, 2023
Copy link
Member

@dantengsky dantengsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's merge

@dantengsky dantengsky merged commit 1ec0585 into databendlabs:main Aug 12, 2023
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));
Copy link
Contributor

@andylokandy andylokandy Aug 13, 2023

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

Copy link
Member Author

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()

Copy link
Contributor

@andylokandy andylokandy Aug 13, 2023

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.

andylokandy pushed a commit to andylokandy/databend that referenced this pull request Nov 27, 2023
* fix: memory leak in unsafe code

* respect gpt advice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: memory leak in unsafe code
3 participants