implemented delete correction for leaks

This commit is contained in:
hugogogo
2022-06-16 18:05:28 +02:00
parent 1cc5dabb7b
commit 5ee4202020
7 changed files with 229 additions and 245 deletions

View File

@@ -138,6 +138,9 @@ VT_TPL void VT::
reserve( size_type new_cap ) {
value_type * tmp_ptr;
value_type * old_ptr = _mem_ptr;
iterator first = begin();
iterator last = end();
if (new_cap > _allocator.max_size())
throw std::length_error("reserve: new_cap > max_size");
@@ -151,10 +154,11 @@ VT_TPL void VT::
if (_mem_ptr)
{
for (size_type i = 0; i < _size; i++)
tmp_ptr[i] = _mem_ptr[i];
_mem_ptr = tmp_ptr;
_size = 0;
assign(first, last);
_destroy(begin(), end());
_allocator.deallocate(_mem_ptr, _capacity);
_allocator.deallocate(old_ptr, _capacity);
}
_mem_ptr = tmp_ptr;
}