Skip to content

Commit 5994a1c

Browse files
haoxian2pcolberg
authored andcommitted
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 60c8012 commit 5994a1c

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/acl_mem.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,7 +4069,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
40694069
cl_event local_event = 0;
40704070
unsigned int physical_id;
40714071
unsigned int mem_id;
4072-
int *needs_release_on_fail;
40734072

40744073
std::scoped_lock lock{acl_mutex_wrapper};
40754074

@@ -4114,10 +4113,7 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41144113

41154114
// Try to reserve space for all the buffers to be moved. If we fail, we need
41164115
// to know which buffers to deallocate:
4117-
needs_release_on_fail = (int *)malloc(sizeof(int) * num_mem_objects);
4118-
for (i = 0; i < num_mem_objects; ++i) {
4119-
needs_release_on_fail[i] = 0;
4120-
}
4116+
std::vector<bool> needs_release_on_fail(num_mem_objects, false);
41214117

41224118
status = CL_SUCCESS;
41234119
for (i = 0; i < num_mem_objects; ++i) {
@@ -4132,7 +4128,7 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41324128
status = CL_MEM_OBJECT_ALLOCATION_FAILURE;
41334129
break;
41344130
}
4135-
needs_release_on_fail[i] = 1;
4131+
needs_release_on_fail[i] = true;
41364132
}
41374133
mem_objects[i]->reserved_allocations_count[physical_id][mem_id]++;
41384134
}
@@ -4148,7 +4144,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41484144
}
41494145
mem_objects[i]->reserved_allocations_count[physical_id][mem_id]--;
41504146
}
4151-
free(needs_release_on_fail);
41524147
return status;
41534148
}
41544149

@@ -4159,7 +4154,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
41594154
CL_COMMAND_MIGRATE_MEM_OBJECTS, &local_event);
41604155

41614156
if (status != CL_SUCCESS) {
4162-
free(needs_release_on_fail);
41634157
return status; // already signalled callback
41644158
}
41654159

@@ -4205,8 +4199,6 @@ ACL_EXPORT CL_API_ENTRY cl_int CL_API_CALL clEnqueueMigrateMemObjectsIntelFPGA(
42054199
acl_idle_update(command_queue->context); // Clean up early
42064200
}
42074201

4208-
free(needs_release_on_fail);
4209-
42104202
return CL_SUCCESS;
42114203
}
42124204

0 commit comments

Comments
 (0)