From 8c2c3d27add5b4eea9ad6d3d52fa1e0d5f7f0974 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 7 Nov 2018 12:28:41 +1100 Subject: [PATCH] Fix memory leak in DualThreadStack Fixes #2556 --- src/regex_impl.hh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/regex_impl.hh b/src/regex_impl.hh index b68ad5d9a..ca686a9cf 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -647,10 +647,12 @@ private: if (m_current != m_next) return; 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]; - std::copy(m_data, m_data + m_current, new_data); - const auto new_next = new_capacity - (m_capacity - m_next); - std::copy(m_data + m_next, m_data + m_capacity, new_data + new_next); + std::copy_n(m_data, m_current, new_data); + std::copy_n(m_data + m_next, next_count, new_data + new_next); + delete[] m_data; m_data = new_data; m_capacity = new_capacity; m_next = new_next;