@@ -97,6 +97,7 @@ static int acl_allocate_block(acl_block_allocation_t *block_allocation,
97
97
static int copy_image_metadata (cl_mem mem);
98
98
static void remove_mem_block_linked_list (acl_block_allocation_t *block);
99
99
static cl_bool is_image (cl_mem mem);
100
+ static void l_free_image_members (cl_mem mem);
100
101
101
102
cl_int acl_convert_image_format (const void *input_element, void *output_element,
102
103
cl_image_format format_from,
@@ -198,6 +199,9 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseMemObjectIntelFPGA(cl_mem mem) {
198
199
--mem->fields .buffer_objs .parent ->fields .buffer_objs .num_subbuffers ;
199
200
clReleaseMemObject (mem->fields .buffer_objs .parent );
200
201
} else {
202
+ if (is_image (mem)) {
203
+ l_free_image_members (mem);
204
+ }
201
205
// The only case wehre mem->region->is_user_provided && mem->host_mem.raw
202
206
// != NULL is when user creates a buffer with CL_MEM_USE_HOST_PTR set and
203
207
// the pointer is allocated with clSVMAlloc.
@@ -6247,6 +6251,23 @@ static cl_bool is_image(cl_mem mem) {
6247
6251
mem->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER);
6248
6252
}
6249
6253
6254
+ static void l_free_image_members (cl_mem mem) {
6255
+ if (mem->fields .image_objs .image_format != NULL ) {
6256
+ acl_free (mem->fields .image_objs .image_format );
6257
+ }
6258
+ if (mem->fields .image_objs .image_desc != NULL ) {
6259
+ if (mem->fields .image_objs .image_desc ->buffer != NULL ) {
6260
+ clReleaseMemObject (mem->fields .image_objs .image_desc ->buffer );
6261
+ mem->fields .image_objs .image_desc ->buffer = NULL ;
6262
+ }
6263
+ if (mem->fields .image_objs .image_desc ->mem_object != NULL ) {
6264
+ clReleaseMemObject (mem->fields .image_objs .image_desc ->mem_object );
6265
+ mem->fields .image_objs .image_desc ->mem_object = NULL ;
6266
+ }
6267
+ acl_free (mem->fields .image_objs .image_desc );
6268
+ }
6269
+ }
6270
+
6250
6271
void acl_copy_device_buffers_to_host_before_programming (
6251
6272
cl_context _context, unsigned int physical_device_id,
6252
6273
void (CL_CALLBACK *read_callback)(cl_mem, int )) {
0 commit comments