Skip to content

Commit 72fd012

Browse files
committed
Fixed coverity issue in acl_mem.cpp: Memory leak
(Line 4172) Missing free for a malloc object before returning, same with (line 4183) Solution: Turning `needs_release_on_fail` into vector since it is only present in the scope of this function
1 parent b9168ed commit 72fd012

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/acl_mem.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ CL_API_ENTRY void *CL_API_CALL clEnqueueMapImageIntelFPGA(
27732773
image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
27742774
if (image_slice_pitch == NULL) {
27752775
BAIL_INFO(CL_INVALID_VALUE, command_queue->context,
2776-
"Invalid slice pitch provided");
2776+
"Invalid slice pitch provided");
27772777
}
27782778
*image_slice_pitch = 0;
27792779
} else if (image->mem_object_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
@@ -2782,7 +2782,7 @@ CL_API_ENTRY void *CL_API_CALL clEnqueueMapImageIntelFPGA(
27822782
*image_slice_pitch =
27832783
image->fields.image_objs.image_desc->image_height * tmp_row_pitch;
27842784
}
2785-
2785+
27862786
tmp_slice_pitch = *image_slice_pitch;
27872787
}
27882788

@@ -4065,7 +4065,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
40654065
cl_event local_event = 0;
40664066
unsigned int physical_id;
40674067
unsigned int mem_id;
4068-
int *needs_release_on_fail;
40694068

40704069
std::scoped_lock lock{acl_mutex_wrapper};
40714070

@@ -4110,10 +4109,7 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41104109

41114110
// Try to reserve space for all the buffers to be moved. If we fail, we need
41124111
// to know which buffers to deallocate:
4113-
needs_release_on_fail = (int *)malloc(sizeof(int) * num_mem_objects);
4114-
for (i = 0; i < num_mem_objects; ++i) {
4115-
needs_release_on_fail[i] = 0;
4116-
}
4112+
std::vector<bool> needs_release_on_fail(num_mem_objects, false);
41174113

41184114
status = CL_SUCCESS;
41194115
for (i = 0; i < num_mem_objects; ++i) {
@@ -4128,7 +4124,7 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41284124
status = CL_MEM_OBJECT_ALLOCATION_FAILURE;
41294125
break;
41304126
}
4131-
needs_release_on_fail[i] = 1;
4127+
needs_release_on_fail[i] = true;
41324128
}
41334129
mem_objects[i]->reserved_allocations_count[physical_id][mem_id]++;
41344130
}
@@ -4144,7 +4140,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41444140
}
41454141
mem_objects[i]->reserved_allocations_count[physical_id][mem_id]--;
41464142
}
4147-
free(needs_release_on_fail);
41484143
return status;
41494144
}
41504145

@@ -4155,7 +4150,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41554150
CL_COMMAND_MIGRATE_MEM_OBJECTS, &local_event);
41564151

41574152
if (status != CL_SUCCESS) {
4158-
free(needs_release_on_fail);
41594153
return status; // already signalled callback
41604154
}
41614155

@@ -4201,8 +4195,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
42014195
acl_idle_update(command_queue->context); // Clean up early
42024196
}
42034197

4204-
free(needs_release_on_fail);
4205-
42064198
return CL_SUCCESS;
42074199
}
42084200

@@ -6824,9 +6816,9 @@ static void acl_dump_mem_internal(cl_mem mem) {
68246816
? "is malloc"
68256817
: "not malloc"));
68266818
printf(" .begin %p\n",
6827-
mem->block_allocation->range.begin);
6819+
mem->block_allocation->range.begin);
68286820
printf(" .end %p\n",
6829-
mem->block_allocation->range.next);
6821+
mem->block_allocation->range.next);
68306822
}
68316823
printf(" .mappings %d\n", mem->mapping_count);
68326824
acl_print_debug_msg(" .size %lu\n", mem->size);

0 commit comments

Comments
 (0)