Fix memory leak when evicting or expiring an entry (v0.7.x) #65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the memory leak issue reported by #64.
The memory leak happens when evicting/expiring an entry or manually invalidating an entry. It should not happen when dropping a cache.
The leaking data is the key of an entry, last modified timestamp (
u64
) and last accessed timestamp (u64
). It does not include the value of an entry.How to reproduce
Deque
's unit tests:Cause
The root cause is forgetting to drop an unlinked
DeqNode
after calling an unsafe methodmoka::common::Deque::unlink
.Fixes
unlink_and_drop
method toDeque
and updated the callers ofunlink
method to callunlink_and_drop
. As the name implies,unlink_and _drop
will unlink theDeqNode
and then drop it.This PR is for the master branch (v0.7.x). There is another PR #66 with the same fixes for the maint-06 branch (v0.6.x).
Affected Versions
Notes
We are not yanking the affected versions at crates.io although this issue will have impact to almost all Moka users, and may lead out of memory error in some use cases. This is because memory leak is not considered a memory safety issue and does not lead undefined behavior (UB).
Instead, we are doing patch releases v0.6.4 and v0.7.1 with the fixes, so that existing v0.6 and v0.7 users will automatically move to one of these fixed versions when
cargo update
is executed.Fixes #64.