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 bad tail state in LRU map on removal of last entry #386

Merged
merged 1 commit into from
Nov 16, 2017

Conversation

cbracken
Copy link
Member

On removal of the last entry from an LRU map, the entry is both _head
and _tail. The existing remove() implementation matched it against
_head, which was then updated to _head.next (null), but _tail was left
unmodified in a bad state.

Since _tail is not null, the next insertion into the newly-empty map
don't reset it. When the map size eventually exceeds the maximum size,
_removeLru() is called to evict _tail, resulting in a null-pointer
exception as _removeLru() attempts to get _tail.previous (null) and then
set .next on that.

On removal of the last entry from an LRU map, the entry is both _head
and _tail. The existing remove() implementation matched it against
_head, which was then updated to _head.next (null), but _tail was left
unmodified in a bad state.

Since _tail is not null, the next insertion into the newly-empty map
don't reset it. When the map size eventually exceeds the maximum size,
_removeLru() is called to evict _tail, resulting in a null-pointer
exception as _removeLru() attempts to get _tail.previous (null) and then
set .next on that.
@cbracken
Copy link
Member Author

Fixes #385.

@cbracken cbracken requested review from yjbanov and a14n November 16, 2017 18:12
Copy link

@tvolkert tvolkert left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1,3 +1,9 @@
#### 0.27.0-dev

Choose a reason for hiding this comment

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

If you plan on releasing this now, then bump the pubspec version as well

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm actually planning to do a trick here and release v0.26.1 since all changes since 0.26.0 are backwards-compatible. Keeping this as-is though since the current pubspec version is 0.27.0-dev and I've got one more update to land since we set the dev version.

Typically we update this value in a release commit that updates the pubspec, the readme and the changelog atomically.

@cbracken cbracken merged commit 9b78f0d into google:master Nov 16, 2017
@cbracken cbracken deleted the lrumap-bug branch November 16, 2017 18:28
@cbracken
Copy link
Member Author

Released in v0.26.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants