shm: Throw RefCountBadAlloc if insufficient space in the ref count segment

This commit is contained in:
Alexey Rybalchenko
2023-11-15 10:10:42 +01:00
parent 961eca5276
commit 424e22b41a
2 changed files with 14 additions and 1 deletions

View File

@@ -279,7 +279,15 @@ class Message final : public fair::mq::Message
}
if (otherMsg.fShared < 0) {
// UR msg not yet shared, create the reference counting object with count 2
otherMsg.fShared = fRegionPtr->HandleFromAddress(&(fRegionPtr->MakeRefCount(2)));
try {
otherMsg.fShared = fRegionPtr->HandleFromAddress(&(fRegionPtr->MakeRefCount(2)));
} catch (boost::interprocess::bad_alloc& ba) {
throw RefCountBadAlloc(tools::ToString(
"Insufficient space in the reference count segment ",
otherMsg.fRegionId,
", original exception: bad_alloc: ",
ba.what()));
}
} else {
fRegionPtr->GetRefCountAddressFromHandle(otherMsg.fShared)->Increment();
}