From 490f37e89680e398f5770c31aca96f0a0a41dc8e Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 13 Sep 2016 13:01:45 +0200 Subject: [PATCH] Memory leakage in vector_queue fixed --- include/WinStd/Common.h | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index 52bd2886..de731c28 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -829,20 +829,29 @@ namespace winstd } } + /// + /// Destroys the queue + /// + virtual ~vector_queue() + { + if (m_data) delete [] m_data; + } + /// /// Moves existing queue. /// /// \param[inout] other Queue to move /// inline vector_queue(_Inout_ vector_queue &&other) : - m_data(std::move(other.m_data)), - m_head(std::move(other.m_head)), - m_count(std::move(other.m_count)), + m_data (std::move(other.m_data )), + m_head (std::move(other.m_head )), + m_count (std::move(other.m_count )), m_size_max(std::move(other.m_size_max)) { // Reset other to consistent state. - other.m_head = 0; - other.m_count = 0; + other.m_data = NULL; + other.m_head = 0; + other.m_count = 0; other.m_size_max = 0; } @@ -859,7 +868,8 @@ namespace winstd m_size_max = other.m_size_max; // Copy elements. - m_data.reset(new value_type[other.m_size_max]); + if (m_data) delete [] m_data; + m_data = new value_type[other.m_size_max]; for (size_type i = 0; i < m_count; i++) { size_type i_l = abs(i); m_data[i_l] = other.m_data[i_l]; @@ -883,8 +893,9 @@ namespace winstd m_size_max = std::move(other.m_size_max); // Reset other to consistent state. - other.m_head = 0; - other.m_count = 0; + other.m_data = NULL; + other.m_head = 0; + other.m_count = 0; other.m_size_max = 0; } @@ -1147,10 +1158,10 @@ namespace winstd } protected: - std::unique_ptr m_data; ///< Underlying data container - size_type m_head; ///< Index of the first element - size_type m_count; ///< Number of elements - size_type m_size_max; ///< Maximum size + value_type *m_data; ///< Underlying data container + size_type m_head; ///< Index of the first element + size_type m_count; ///< Number of elements + size_type m_size_max; ///< Maximum size };