lru: Fix lookup race on small caches.
lru: Fix lookup race on small caches.

This fixes a possible race condition that could happen between the Add
and Lookup calls when the cache size was small.

When an entry was found in the cache during a Lookup call, its value
was fetched from the internal list node outside the mutex lock. This
could race with a corresponding Add call when the node was actually
the LRU node and was about to be overwritten.

This could manifest as a race specially when using caches with a very
small size, since it becomes more likely to perform a lookup on an entry
that is about to be concurrently overwritten.

This fixes the issue by moving the code that extracts the value from the
node to be performed with the lock held.
decred/dcrd,decred/dcrd