Fix memory leak in DualThreadStack

Fixes #2556
This commit is contained in:
Maxime Coste 2018-11-07 12:28:41 +11:00
parent 9bc893e70b
commit 8c2c3d27ad

View File

@ -647,10 +647,12 @@ private:
if (m_current != m_next) if (m_current != m_next)
return; return;
const auto new_capacity = m_capacity ? m_capacity * 2 : 4; const auto new_capacity = m_capacity ? m_capacity * 2 : 4;
const auto next_count = m_capacity - m_next;
const auto new_next = new_capacity - next_count;
Thread* new_data = new Thread[new_capacity]; Thread* new_data = new Thread[new_capacity];
std::copy(m_data, m_data + m_current, new_data); std::copy_n(m_data, m_current, new_data);
const auto new_next = new_capacity - (m_capacity - m_next); std::copy_n(m_data + m_next, next_count, new_data + new_next);
std::copy(m_data + m_next, m_data + m_capacity, new_data + new_next); delete[] m_data;
m_data = new_data; m_data = new_data;
m_capacity = new_capacity; m_capacity = new_capacity;
m_next = new_next; m_next = new_next;