Skip to content

Commit 509ebe4

Browse files
authored
Merge pull request #780 from jszuppe/fix_memory_leak_746
Fix memory leak
2 parents b0f5bfc + 58bf866 commit 509ebe4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

include/boost/compute/iterator/buffer_iterator.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ struct buffer_iterator_index_expr
6565
{
6666
}
6767

68+
buffer_iterator_index_expr(const buffer_iterator_index_expr& other)
69+
: m_buffer(other.m_buffer.get(), false),
70+
m_index(other.m_index),
71+
m_address_space(other.m_address_space),
72+
m_expr(other.m_expr)
73+
{
74+
}
75+
6876
~buffer_iterator_index_expr()
6977
{
7078
// set buffer to null so that its reference count will

test/test_reduce.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,23 @@ BOOST_AUTO_TEST_CASE(reduce_uchar_to_float)
276276
BOOST_CHECK_EQUAL(sum, 500);
277277
}
278278

279+
// Test case for https://github.com/boostorg/compute/issues/746
280+
BOOST_AUTO_TEST_CASE(buffer_reference_count_test)
281+
{
282+
using compute::uint_;
283+
284+
compute::vector<uint_> vector(8, context);
285+
const compute::buffer& b = vector.get_buffer();
286+
uint_ rc1 = b.get_info<CL_MEM_REFERENCE_COUNT>();
287+
{
288+
compute::fill(vector.begin(), vector.end(), uint_(2), queue);
289+
290+
uint_ product;
291+
compute::reduce(vector.begin(), vector.end(), &product, compute::multiplies<uint_>(), queue);
292+
BOOST_CHECK_EQUAL(product, uint_(256));
293+
}
294+
uint_ rc2 = b.get_info<CL_MEM_REFERENCE_COUNT>();
295+
BOOST_CHECK_EQUAL(rc1, rc2);
296+
}
297+
279298
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)