-
Notifications
You must be signed in to change notification settings - Fork 398
fix(core): Memory leak bugs in CheckPoint::drop
impl
#1997
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
base: master
Are you sure you want to change the base?
fix(core): Memory leak bugs in CheckPoint::drop
impl
#1997
Conversation
Fix memory leak bug in `CheckPoint::drop` by using `Arc::into_inner` if it is available (>= 1.70). Fix `CPInner::drop` logic so that if `CPInner::block` becomes generic and is of a type that required `drop`, it does not leak memory. Add tests for memory leak + stack overflow when dropping `CheckPoint`.
f7632fb
to
4401886
Compare
// Don't call `drop` on `CPInner` since that risks it becoming recursive. | ||
core::mem::forget(node); |
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.
Rationale for removal:
core::mem::forget
is dangerous if CPInner::block
is generic since the type might require a call to drop
. This is not possible now, however it's best to remove it now to avoid forgetting about it later on.
The initial motivation for calling forget
is to ensure no recursion happens. However, the recursive depth would always only be 1 since prev
is None
. Thus, there is no risk of stack overflow (proven by the checkpoint_drop_is_not_recursive
test that is added).
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.
ACK 4401886
if version_check::is_min_version("1.70.0").unwrap_or(false) { | ||
println!("cargo:rustc-cfg=has_arc_into_inner"); | ||
} | ||
} |
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.
IMO this is slightly overkill and we can wait until MSRV is at least 1.70.0 to use Arc::into_inner
.
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.
Memory leaks aren't fun though.
FWIW, bumping MSRV to 1.75 would be fine by us, especially if it allows you guys to avoid these kinds of complications (also cf. #1750) |
Description
CheckPoint::drop
by usingArc::into_inner
if it is available (>= 1.70).CPInner::drop
logic so that ifCPInner::block
becomes generic and is of a type that requireddrop
, it does not leak memory.CheckPoint
.An alternative fix is to bump MSRV to >= 1.70 so we don't need to do conditional compilation based on version.
Changelog notice
Checklists
All Submissions:
Bugfixes: