logic: Fixing a crash in SharedMemory::ScopedAccess use (#912)

Co-authored-by: Eberhard Gräther <egraether@coati.io>
This commit is contained in:
Timothee "TTimo" Besset
2020-03-02 12:23:57 +01:00
committed by GitHub
co-authored by Eberhard Gräther
parent 5e475b75c8
commit f4b37f9763
+25 -1
View File
@@ -8,10 +8,34 @@ const char* SharedMemory::s_mutexNamePrefix = "srctrlmtx_";
SharedMemory::ScopedAccess::ScopedAccess(SharedMemory* memory)
: boost::interprocess::scoped_lock<boost::interprocess::named_mutex>(memory->getMutex())
, m_memory(boost::interprocess::open_only, memory->getMemoryName().c_str())
//, m_memory(boost::interprocess::open_only, memory->getMemoryName().c_str())
, m_memoryName(memory->getMemoryName())
, m_minimumMemorySize(memory->getInitialMemorySize())
{
try
{
m_memory = boost::interprocess::managed_shared_memory(boost::interprocess::open_only, memory->getMemoryName().c_str());
}
catch (boost::interprocess::interprocess_exception& e)
{
LOG_ERROR_STREAM(
<< "boost exception thrown at ScopedAccess constructor - " << memory->getMemoryName() << ": "
<< e.what());
// Behaves the same as the initializer construction, with the error printed out
//throw e;
boost::interprocess::permissions permissions;
permissions.set_unrestricted();
m_memory = boost::interprocess::managed_shared_memory(
boost::interprocess::open_or_create,
memory->getMemoryName().c_str(),
memory->getInitialMemorySize(),
0,
permissions
);
}
}
SharedMemory::ScopedAccess::~ScopedAccess() {}