aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2014-10-09 23:35:05 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2014-10-09 23:35:05 +0200
commit538c059aa4d02a9f1a282e8fc4b181c8eb0b4f47 (patch)
treec3403184426c043bb837c4da2bcbdac878b0bd68 /Eigen/src
parenta48b82eece435e24418beb95f16ab32be7970183 (diff)
bug #887: fix CompressedStorage::reallocate wrt memory leaks
Diffstat (limited to 'Eigen/src')
-rw-r--r--Eigen/src/SparseCore/CompressedStorage.h17
1 files changed, 7 insertions, 10 deletions
diff --git a/Eigen/src/SparseCore/CompressedStorage.h b/Eigen/src/SparseCore/CompressedStorage.h
index a93550340..4f3695773 100644
--- a/Eigen/src/SparseCore/CompressedStorage.h
+++ b/Eigen/src/SparseCore/CompressedStorage.h
@@ -204,17 +204,14 @@ class CompressedStorage
inline void reallocate(size_t size)
{
- Scalar* newValues = new Scalar[size];
- Index* newIndices = new Index[size];
+ eigen_internal_assert(size!=m_allocatedSize);
+ internal::scoped_array<Scalar> newValues(size);
+ internal::scoped_array<Index> newIndices(size);
size_t copySize = (std::min)(size, m_size);
- // copy
- internal::smart_copy(m_values, m_values+copySize, newValues);
- internal::smart_copy(m_indices, m_indices+copySize, newIndices);
- // delete old stuff
- delete[] m_values;
- delete[] m_indices;
- m_values = newValues;
- m_indices = newIndices;
+ internal::smart_copy(m_values, m_values+copySize, newValues.ptr());
+ internal::smart_copy(m_indices, m_indices+copySize, newIndices.ptr());
+ std::swap(m_values,newValues.ptr());
+ std::swap(m_indices,newIndices.ptr());
m_allocatedSize = size;
}