mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-02 17:06:00 +00:00
Fix exception safety in aged containers
This commit is contained in:
@@ -389,11 +389,26 @@ private:
|
|||||||
template <class... Args>
|
template <class... Args>
|
||||||
element* new_element (Args&&... args)
|
element* new_element (Args&&... args)
|
||||||
{
|
{
|
||||||
element* const p (
|
struct Deleter
|
||||||
ElementAllocatorTraits::allocate (m_config.alloc(), 1));
|
{
|
||||||
|
std::reference_wrapper <ElementAllocator> a_;
|
||||||
|
Deleter (ElementAllocator& a)
|
||||||
|
: a_(a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
operator()(element* p)
|
||||||
|
{
|
||||||
|
ElementAllocatorTraits::deallocate (a_.get(), p, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr <element, Deleter> p (ElementAllocatorTraits::allocate (
|
||||||
|
m_config.alloc(), 1), Deleter(m_config.alloc()));
|
||||||
ElementAllocatorTraits::construct (m_config.alloc(),
|
ElementAllocatorTraits::construct (m_config.alloc(),
|
||||||
p, clock().now(), std::forward <Args> (args)...);
|
p.get(), clock().now(), std::forward <Args> (args)...);
|
||||||
return p;
|
return p.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_element (element const* p)
|
void delete_element (element const* p)
|
||||||
|
|||||||
@@ -577,11 +577,26 @@ private:
|
|||||||
template <class... Args>
|
template <class... Args>
|
||||||
element* new_element (Args&&... args)
|
element* new_element (Args&&... args)
|
||||||
{
|
{
|
||||||
element* const p (
|
struct Deleter
|
||||||
ElementAllocatorTraits::allocate (m_config.alloc(), 1));
|
{
|
||||||
|
std::reference_wrapper <ElementAllocator> a_;
|
||||||
|
Deleter (ElementAllocator& a)
|
||||||
|
: a_(a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
operator()(element* p)
|
||||||
|
{
|
||||||
|
ElementAllocatorTraits::deallocate (a_.get(), p, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr <element, Deleter> p (ElementAllocatorTraits::allocate (
|
||||||
|
m_config.alloc(), 1), Deleter(m_config.alloc()));
|
||||||
ElementAllocatorTraits::construct (m_config.alloc(),
|
ElementAllocatorTraits::construct (m_config.alloc(),
|
||||||
p, clock().now(), std::forward <Args> (args)...);
|
p.get(), clock().now(), std::forward <Args> (args)...);
|
||||||
return p;
|
return p.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_element (element const* p)
|
void delete_element (element const* p)
|
||||||
|
|||||||
Reference in New Issue
Block a user