Skip to content

Commit 207bd89

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 207bd89

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/acl_mem.cpp

Lines changed: 6 additions & 11 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,7 @@ 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;
4068+
std::vector<int> needs_release_on_fail;
40694069

40704070
std::scoped_lock lock{acl_mutex_wrapper};
40714071

@@ -4110,9 +4110,8 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41104110

41114111
// Try to reserve space for all the buffers to be moved. If we fail, we need
41124112
// to know which buffers to deallocate:
4113-
needs_release_on_fail = (int *)malloc(sizeof(int) * num_mem_objects);
41144113
for (i = 0; i < num_mem_objects; ++i) {
4115-
needs_release_on_fail[i] = 0;
4114+
needs_release_on_fail.push_back(0);
41164115
}
41174116

41184117
status = CL_SUCCESS;
@@ -4144,7 +4143,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41444143
}
41454144
mem_objects[i]->reserved_allocations_count[physical_id][mem_id]--;
41464145
}
4147-
free(needs_release_on_fail);
41484146
return status;
41494147
}
41504148

@@ -4155,7 +4153,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41554153
CL_COMMAND_MIGRATE_MEM_OBJECTS, &local_event);
41564154

41574155
if (status != CL_SUCCESS) {
4158-
free(needs_release_on_fail);
41594156
return status; // already signalled callback
41604157
}
41614158

@@ -4201,8 +4198,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
42014198
acl_idle_update(command_queue->context); // Clean up early
42024199
}
42034200

4204-
free(needs_release_on_fail);
4205-
42064201
return CL_SUCCESS;
42074202
}
42084203

@@ -6824,9 +6819,9 @@ static void acl_dump_mem_internal(cl_mem mem) {
68246819
? "is malloc"
68256820
: "not malloc"));
68266821
printf(" .begin %p\n",
6827-
mem->block_allocation->range.begin);
6822+
mem->block_allocation->range.begin);
68286823
printf(" .end %p\n",
6829-
mem->block_allocation->range.next);
6824+
mem->block_allocation->range.next);
68306825
}
68316826
printf(" .mappings %d\n", mem->mapping_count);
68326827
acl_print_debug_msg(" .size %lu\n", mem->size);

0 commit comments

Comments
 (0)