mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Fix buffer tests memory leaks (#1165)
* Fix buffer tests memory leaks This change fixes buffer tests, broken by PR #1082. This pull request is similar to #1160 * Fix formatting
This commit is contained in:
committed by
GitHub
parent
fc67d7b28f
commit
8b5d3c2055
@@ -554,7 +554,6 @@ static int verify_read_struct( void *ptr, int n )
|
||||
static int test_buffer_map_read( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, size_t size, char *type, int loops,
|
||||
const char *kernelCode[], const char *kernelName[], int (*fn)(void *,int) )
|
||||
{
|
||||
clMemWrapper buffers[5];
|
||||
void *outptr[5];
|
||||
clProgramWrapper program[5];
|
||||
clKernelWrapper kernel[5];
|
||||
@@ -593,7 +592,7 @@ static int test_buffer_map_read( cl_device_id deviceID, cl_context context, cl_c
|
||||
|
||||
for (src_flag_id = 0; src_flag_id < NUM_FLAGS; src_flag_id++)
|
||||
{
|
||||
|
||||
clMemWrapper buffer;
|
||||
outptr[i] = align_malloc( ptrSizes[i] * num_elements, min_alignment);
|
||||
if ( ! outptr[i] ){
|
||||
log_error( " unable to allocate %d bytes of memory\n", (int)ptrSizes[i] * num_elements );
|
||||
@@ -601,18 +600,22 @@ static int test_buffer_map_read( cl_device_id deviceID, cl_context context, cl_c
|
||||
}
|
||||
|
||||
if ((flag_set[src_flag_id] & CL_MEM_USE_HOST_PTR) || (flag_set[src_flag_id] & CL_MEM_COPY_HOST_PTR))
|
||||
buffers[i] = clCreateBuffer(context, flag_set[src_flag_id], ptrSizes[i] * num_elements, outptr[i], &err);
|
||||
buffer =
|
||||
clCreateBuffer(context, flag_set[src_flag_id],
|
||||
ptrSizes[i] * num_elements, outptr[i], &err);
|
||||
else
|
||||
buffers[i] = clCreateBuffer(context, flag_set[src_flag_id], ptrSizes[i] * num_elements, NULL, &err);
|
||||
buffer = clCreateBuffer(context, flag_set[src_flag_id],
|
||||
ptrSizes[i] * num_elements, NULL, &err);
|
||||
|
||||
if (!buffers[i] || err)
|
||||
if (!buffer || err)
|
||||
{
|
||||
print_error(err, "clCreateBuffer failed\n" );
|
||||
align_free( outptr[i] );
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = clSetKernelArg( kernel[i], 0, sizeof( cl_mem ), (void *)&buffers[i] );
|
||||
err = clSetKernelArg(kernel[i], 0, sizeof(cl_mem), (void *)&buffer);
|
||||
|
||||
if ( err != CL_SUCCESS ){
|
||||
print_error( err, "clSetKernelArg failed\n" );
|
||||
align_free( outptr[i] );
|
||||
@@ -631,8 +634,11 @@ static int test_buffer_map_read( cl_device_id deviceID, cl_context context, cl_c
|
||||
return -1;
|
||||
}
|
||||
|
||||
mappedPtr = clEnqueueMapBuffer(queue, buffers[i], CL_TRUE, CL_MAP_READ, 0, ptrSizes[i]*num_elements, 0, NULL, NULL, &err);
|
||||
if ( err != CL_SUCCESS ){
|
||||
mappedPtr = clEnqueueMapBuffer(queue, buffer, CL_TRUE, CL_MAP_READ,
|
||||
0, ptrSizes[i] * num_elements, 0,
|
||||
NULL, NULL, &err);
|
||||
if (err != CL_SUCCESS)
|
||||
{
|
||||
print_error( err, "clEnqueueMapBuffer failed" );
|
||||
align_free( outptr[i] );
|
||||
return -1;
|
||||
@@ -648,7 +654,8 @@ static int test_buffer_map_read( cl_device_id deviceID, cl_context context, cl_c
|
||||
1 << i, flag_set_names[src_flag_id]);
|
||||
}
|
||||
|
||||
err = clEnqueueUnmapMemObject(queue, buffers[i], mappedPtr, 0, NULL, NULL);
|
||||
err = clEnqueueUnmapMemObject(queue, buffer, mappedPtr, 0, NULL,
|
||||
NULL);
|
||||
test_error(err, "clEnqueueUnmapMemObject failed");
|
||||
|
||||
// If we are using the outptr[i] as backing via USE_HOST_PTR we need to make sure we are done before freeing.
|
||||
|
||||
Reference in New Issue
Block a user