mirror of
https://github.com/holub/mame
synced 2025-05-29 17:13:05 +03:00
netlist/plib: Fix memory leak when exception is thrown in constructor.
This commit is contained in:
parent
56f9e77b84
commit
7cc3012c22
@ -300,12 +300,29 @@ namespace plib {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<typename T, typename... Args>
|
||||
owned_pool_ptr<T> make_poolptr(Args&&... args)
|
||||
{
|
||||
auto *mem = allocate(alignof(T), sizeof(T));
|
||||
return owned_pool_ptr<T>(new (mem) T(std::forward<Args>(args)...), true, arena_deleter<aligned_arena, T>(*this));
|
||||
}
|
||||
#endif
|
||||
template<typename T, typename... Args>
|
||||
owned_pool_ptr<T> make_poolptr(Args&&... args)
|
||||
{
|
||||
auto *mem = allocate(alignof(T), sizeof(T));
|
||||
try
|
||||
{
|
||||
auto *mema = new (mem) T(std::forward<Args>(args)...);
|
||||
return owned_pool_ptr<T>(mema, true, arena_deleter<aligned_arena, T>(*this));
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
deallocate(mem);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -168,7 +168,6 @@ namespace plib {
|
||||
{
|
||||
b->m_num_alloc--;
|
||||
//printf("Freeing in block %p %lu\n", b, b->m_num_alloc);
|
||||
sinfo().erase(it);
|
||||
if (b->m_num_alloc == 0)
|
||||
{
|
||||
mempool *mp = b->m_mempool;
|
||||
@ -179,6 +178,7 @@ namespace plib {
|
||||
mp->m_blocks.erase(itb);
|
||||
plib::pdelete(b);
|
||||
}
|
||||
sinfo().erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +189,16 @@ namespace plib {
|
||||
owned_pool_ptr<T> make_poolptr(Args&&... args)
|
||||
{
|
||||
auto *mem = this->allocate(alignof(T), sizeof(T));
|
||||
return owned_pool_ptr<T>(new (mem) T(std::forward<Args>(args)...), true, arena_deleter<mempool, T>(this));
|
||||
try
|
||||
{
|
||||
auto *mema = new (mem) T(std::forward<Args>(args)...);
|
||||
return owned_pool_ptr<T>(mema, true, arena_deleter<mempool, T>(this));
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
this->deallocate(mem);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user