diff --git a/src/Cache_inode/cache_inode_lru.c b/src/Cache_inode/cache_inode_lru.c index 494fc6a309..1686342853 100644 --- a/src/Cache_inode/cache_inode_lru.c +++ b/src/Cache_inode/cache_inode_lru.c @@ -536,6 +536,7 @@ lru_try_reap_entry(struct lru_q_base *q) if (lru->refcount > LRU_SENTINEL_REFCOUNT + 1) { /* Someone took a reference while we were waiting for the queue. */ + --(lru->refcount); pthread_mutex_unlock(&lru->mtx); pthread_mutex_unlock(&q->mtx); return NULL; @@ -1161,6 +1162,7 @@ cache_inode_lru_get(cache_inode_client_t *client, "pthread_mutex_init of lru.mtx returned %d (%s)", errno, strerror(errno)); + entry = NULL; *status = CACHE_INODE_INIT_ENTRY_FAILED; goto out; } diff --git a/src/Cache_inode/cache_inode_misc.c b/src/Cache_inode/cache_inode_misc.c index d889f06bb6..1d2b0f81ed 100644 --- a/src/Cache_inode/cache_inode_misc.c +++ b/src/Cache_inode/cache_inode_misc.c @@ -265,6 +265,7 @@ cache_inode_new_entry(cache_inode_fsal_data_t *fsdata, *status = CACHE_INODE_MALLOC_ERROR; goto out; } + assert(entry->lru.refcount > 1); /* This should be the sentinel, plus one to use the entry we just returned. */ lrurefed = TRUE; @@ -444,7 +445,7 @@ cache_inode_new_entry(cache_inode_fsal_data_t *fsdata, if (latched) { HashTable_ReleaseLatched(fh_to_cache_entry_ht, &latch); } - if (lrurefed) { + if (lrurefed && *status != CACHE_INODE_ENTRY_EXISTS) { cache_inode_lru_unref(entry, client, LRU_FLAG_NONE); } if (*status != CACHE_INODE_ENTRY_EXISTS) {