2
0
mirror of https://github.com/boostorg/compute.git synced 2026-01-26 18:32:48 +00:00

Merge pull request #780 from jszuppe/fix_memory_leak_746

Fix memory leak
This commit is contained in:
Jakub Szuppe
2018-05-13 22:14:06 +02:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

View File

@@ -65,6 +65,14 @@ struct buffer_iterator_index_expr
{
}
buffer_iterator_index_expr(const buffer_iterator_index_expr& other)
: m_buffer(other.m_buffer.get(), false),
m_index(other.m_index),
m_address_space(other.m_address_space),
m_expr(other.m_expr)
{
}
~buffer_iterator_index_expr()
{
// set buffer to null so that its reference count will

View File

@@ -276,4 +276,23 @@ BOOST_AUTO_TEST_CASE(reduce_uchar_to_float)
BOOST_CHECK_EQUAL(sum, 500);
}
// Test case for https://github.com/boostorg/compute/issues/746
BOOST_AUTO_TEST_CASE(buffer_reference_count_test)
{
using compute::uint_;
compute::vector<uint_> vector(8, context);
const compute::buffer& b = vector.get_buffer();
uint_ rc1 = b.get_info<CL_MEM_REFERENCE_COUNT>();
{
compute::fill(vector.begin(), vector.end(), uint_(2), queue);
uint_ product;
compute::reduce(vector.begin(), vector.end(), &product, compute::multiplies<uint_>(), queue);
BOOST_CHECK_EQUAL(product, uint_(256));
}
uint_ rc2 = b.get_info<CL_MEM_REFERENCE_COUNT>();
BOOST_CHECK_EQUAL(rc1, rc2);
}
BOOST_AUTO_TEST_SUITE_END()