mCRL2org/mCRL2

ATerms are being leaked due to construction and destruction threads not matching, .e.g., in lpsxsim.

mlaveaux opened this issue · 0 comments

Currently term destructions are silently ignored when they do not occur in the protection set.

template <class Key, typename Hash, typename Equals, typename Allocator>
inline typename hashtable<Key,Hash,Equals,Allocator>::iterator hashtable<Key,Hash,Equals,Allocator>::erase(const Key& key)
{
const std::size_t key_index = get_index(key);
auto it = begin() + key_index;
// Find the key.
while (!m_equals(*it, key))
{
++it;
if (it == end())
{
it = begin();
}
if (it == begin() + key_index)
{
// An element not in the hashset is begin removed.
// When optimizing, the gcc compiler tends to generate
// destructions of non generated aterms. If this is
// repaired, this safety escape can be removed.
return it;
}
assert(it != begin() + key_index);
}
*it = nullptr;
--m_number_of_elements;
return it;
}

Disabling this 'safety' escape reveals subtle bugs in how tools interact with the protection sets. One example being that lpxsim creates the Simulation' in the main thread, and then tries to read in an other LPS in a Qt event call ran on a separate thread. This IO operation will delete the original m_stochastic_spec', which was created during initialisation. This results in that ATerm being leaked as it will never be removed from it's original protection set.