Skip to content

Commit 93ad270

Browse files
committed
Avoid calling destroy in the destructor of a vector if the vector is empty.
Bug 2720132
1 parent b36f2c9 commit 93ad270

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

thrust/detail/vector_base.inl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ template<typename T, typename Alloc>
556556
::~vector_base(void)
557557
{
558558
// destroy every living thing
559-
m_storage.destroy(begin(),end());
559+
if (!empty())
560+
m_storage.destroy(begin(),end());
560561
} // end vector_base::~vector_base()
561562

562563
template<typename T, typename Alloc>
@@ -1028,7 +1029,7 @@ template<typename T, typename Alloc>
10281029
{
10291030
*current = *first;
10301031
} // end for
1031-
1032+
10321033
// either just the input was exhausted or both
10331034
// the input and vector elements were exhausted
10341035
if(first == last)
@@ -1079,7 +1080,7 @@ template<typename T, typename Alloc>
10791080
{
10801081
// range fits inside allocated storage, but some elements
10811082
// have not been constructed yet
1082-
1083+
10831084
// XXX TODO we could possibly implement this with one call
10841085
// to transform rather than copy + uninitialized_copy
10851086

@@ -1161,7 +1162,7 @@ template<typename T, typename Alloc>
11611162
} // end try
11621163
catch(...)
11631164
{
1164-
// something went wrong, so destroy & deallocate the new storage
1165+
// something went wrong, so destroy & deallocate the new storage
11651166
// XXX seems like this destroys too many elements -- should just be last - first instead of requested_size
11661167
iterator new_storage_end = new_storage.begin();
11671168
thrust::advance(new_storage_end, requested_size);
@@ -1187,7 +1188,7 @@ template<typename T, typename Alloc>
11871188

11881189
namespace detail
11891190
{
1190-
1191+
11911192
// iterator tags match
11921193
template <typename InputIterator1, typename InputIterator2>
11931194
bool vector_equal(InputIterator1 first1, InputIterator1 last1,
@@ -1243,7 +1244,7 @@ bool operator==(const detail::vector_base<T1,Alloc1>& lhs,
12431244
{
12441245
return lhs.size() == rhs.size() && detail::vector_equal(lhs.begin(), lhs.end(), rhs.begin());
12451246
}
1246-
1247+
12471248
template<typename T1, typename Alloc1,
12481249
typename T2, typename Alloc2>
12491250
bool operator==(const detail::vector_base<T1,Alloc1>& lhs,
@@ -1267,7 +1268,7 @@ bool operator!=(const detail::vector_base<T1,Alloc1>& lhs,
12671268
{
12681269
return !(lhs == rhs);
12691270
}
1270-
1271+
12711272
template<typename T1, typename Alloc1,
12721273
typename T2, typename Alloc2>
12731274
bool operator!=(const detail::vector_base<T1,Alloc1>& lhs,

0 commit comments

Comments
 (0)