mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-05-09 22:39:05 +08:00
bug #887: fix CompressedStorage::reallocate wrt memory leaks
This commit is contained in:
parent
a48b82eece
commit
538c059aa4
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user