Skip to content

fix: guard LRUCache against non-positive capacity - #1749

Merged
hsluoyz merged 3 commits into
apache:masterfrom
nikolauspschuetz:fix/lrucache-non-positive-capacity
Aug 21, 2026
Merged

fix: guard LRUCache against non-positive capacity#1749
hsluoyz merged 3 commits into
apache:masterfrom
nikolauspschuetz:fix/lrucache-non-positive-capacity

Conversation

@nikolauspschuetz

@nikolauspschuetz nikolauspschuetz commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

No description provided.

NewLRUCache and NewSyncLRUCache are exported, but calling Put on a cache
created with a non-positive capacity panicked with a nil pointer
dereference: the eviction path removes cache.tail.prev, which on an empty
list is the head sentinel whose prev pointer is nil.

Return early from Put when capacity is non-positive, since such a cache
holds nothing. Add a regression test that fails (panics) before this
change and passes after.
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review August 16, 2026 15:12
@hsluoyz
hsluoyz merged commit b8c049a into apache:master Aug 21, 2026
3 checks passed
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.

2 participants