1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-17 01:56:16 +02:00

crucible: fix further instances of copy-after-unlock bug

Before:

	unique_lock<mutex> lock(some_mutex);
	// run lock.~unique_lock() because return
	// return reference to unprotected heap
	return foo[bar];

After:

	unique_lock<mutex> lock(some_mutex);
	// make copy of object on heap protected by mutex lock
	auto tmp_copy = foo[bar];
	// run lock.~unique_lock() because return
	// pass locally allocated object to copy constructor
	return tmp_copy;

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell
2017-01-22 21:50:21 -05:00
parent c58e5cd75b
commit 6099bf0b01
3 changed files with 15 additions and 5 deletions

View File

@ -124,7 +124,9 @@ namespace crucible {
if (m_set.empty()) {
return key_type();
} else {
return *m_set.begin();
// Make copy with lock held
auto rv = *m_set.begin();
return rv;
}
}
@ -149,7 +151,8 @@ namespace crucible {
WorkQueue<Task>::copy()
{
unique_lock<mutex> lock(m_mutex);
return m_set;
auto rv = m_set;
return rv;
}
template <class Task>