Skip to content
Snippets Groups Projects
Unverified Commit 24b73981 authored by Eelco Dolstra's avatar Eelco Dolstra
Browse files

Fix double free in Store::queryPathInfo()

It was holding on to a Value* (i.e. a std::shared_ptr<ValidPathInfo>*)
outside of the pathInfoCache lock, so the std::shared_ptr could be
destroyed between the release of the lock and the decrement of the
std::shared_ptr refcount. This can happen if more than
'path-info-cache-size' paths are added in the meantime, *or* if
clearPathInfoCache() is called. The hydra-queue-runner queue monitor
thread periodically calls the later, so is likely to trigger a crash.

Fixes https://github.com/NixOS/hydra/issues/542.
parent dc83c8ee
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
#include <map>
#include <list>
#include <experimental/optional>
namespace nix {
......@@ -63,18 +64,17 @@ public:
/* Look up an item in the cache. If it exists, it becomes the most
recently used item. */
// FIXME: use boost::optional?
Value * get(const Key & key)
std::experimental::optional<Value> get(const Key & key)
{
auto i = data.find(key);
if (i == data.end()) return 0;
if (i == data.end()) return {};
/* Move this item to the back of the LRU list. */
lru.erase(i->second.first.it);
auto j = lru.insert(lru.end(), i);
i->second.first.it = j;
return &i->second.second;
return i->second.second;
}
size_t size()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment