Skip to content

Commit 8f33d10

Browse files
committed
Fix CID 1393670 (Resource leak)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 12a601f commit 8f33d10

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/opencl/openclwrapper.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,6 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
10131013
size_t source_size[1];
10141014
int b_error, binary_status, binaryExisted, idx;
10151015
cl_uint numDevices;
1016-
cl_device_id *mpArryDevsID;
10171016
FILE *fd, *fd1;
10181017
const char* filename = "kernel.cl";
10191018
//fprintf(stderr, "[OD] CompileKernelFile ... \n");
@@ -1036,10 +1035,7 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
10361035
sizeof(numDevices), &numDevices, nullptr);
10371036
CHECK_OPENCL(clStatus, "clGetContextInfo");
10381037

1039-
mpArryDevsID = (cl_device_id *)malloc(sizeof(cl_device_id) * numDevices);
1040-
if (mpArryDevsID == nullptr) {
1041-
return 0;
1042-
}
1038+
std::vector<cl_device_id> mpArryDevsID(numDevices);
10431039
//PERF_COUNT_SUB("get numDevices")
10441040
b_error = 0;
10451041
length = 0;
@@ -1062,18 +1058,16 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
10621058
// grab the handles to all of the devices in the context.
10631059
clStatus = clGetContextInfo(gpuInfo->mpContext, CL_CONTEXT_DEVICES,
10641060
sizeof(cl_device_id) * numDevices,
1065-
mpArryDevsID, nullptr);
1061+
&mpArryDevsID[0], nullptr);
10661062
CHECK_OPENCL( clStatus, "clGetContextInfo" );
10671063
//PERF_COUNT_SUB("get devices")
10681064
//fprintf(stderr, "[OD] Create kernel from binary\n");
10691065
const uint8_t *c_binary = &binary[0];
10701066
gpuInfo->mpArryPrograms[idx] = clCreateProgramWithBinary( gpuInfo->mpContext,numDevices,
1071-
mpArryDevsID, &length, &c_binary,
1067+
&mpArryDevsID[0], &length, &c_binary,
10721068
&binary_status, &clStatus );
10731069
CHECK_OPENCL( clStatus, "clCreateProgramWithBinary" );
10741070
//PERF_COUNT_SUB("clCreateProgramWithBinary")
1075-
free( mpArryDevsID );
1076-
mpArryDevsID = nullptr;
10771071
// PERF_COUNT_SUB("binaryExisted")
10781072
}
10791073
else

0 commit comments

Comments
 (0)