Permalink
Browse files

don't fetch yourself during memory allocation

It was possible to, while replacing an item, find your own item from the tail
and examine it. This reverse some logic and adds a not-completely-covering
check of ignoring an item if it has the same (complete) hash value.

This is the second half of the general fix for the infamous "issue 260" from
google code bugs.
  • Loading branch information...
1 parent 59bd02c commit fd39b1953b04b7dd9fdfe9a4f0d69e2225095ba0 @dormando dormando committed Apr 28, 2014
Showing with 2 additions and 2 deletions.
  1. +2 −2 items.c
View
@@ -123,8 +123,8 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags,
/* Attempt to hash item lock the "search" item. If locked, no
* other callers can incr the refcount
*/
- /* FIXME: I think we need to mask the hv here for comparison? */
- if (hv != cur_hv && (hold_lock = item_trylock(hv)) == NULL)
+ /* Don't accidentally grab ourselves, or bail if we can't quicklock */
+ if (hv == cur_hv || (hold_lock = item_trylock(hv)) == NULL)
continue;
/* Now see if the item is refcount locked */
if (refcount_incr(&search->refcount) != 2) {

0 comments on commit fd39b19

Please sign in to comment.