Skip to content

Commit 53596f7

Browse files
committed
Fix CID 1393662 (Resource leak)
Signed-off-by: Stefan Weil <[email protected]>
1 parent fcff2f2 commit 53596f7

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/opencl/openclwrapper.cpp

+6-11
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
10081008
//PERF_COUNT_START("CompileKernelFile")
10091009
cl_int clStatus = 0;
10101010
size_t length;
1011-
char *buildLog = nullptr, *binary;
1011+
char *buildLog = nullptr;
10121012
const char *source;
10131013
size_t source_size[1];
10141014
int b_error, binary_status, binaryExisted, idx;
@@ -1051,15 +1051,10 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
10511051
return 0;
10521052
}
10531053

1054-
binary = (char*) malloc( length + 2 );
1055-
if ( !binary )
1056-
{
1057-
return 0;
1058-
}
1059-
1060-
memset( binary, 0, length + 2 );
1061-
b_error |= fread( binary, 1, length, fd ) != length;
1054+
std::vector<uint8_t> binary(length + 2);
10621055

1056+
memset(&binary[0], 0, length + 2);
1057+
b_error |= fread(&binary[0], 1, length, fd) != length;
10631058

10641059
fclose( fd );
10651060
//PERF_COUNT_SUB("read file")
@@ -1071,12 +1066,12 @@ int OpenclDevice::CompileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
10711066
CHECK_OPENCL( clStatus, "clGetContextInfo" );
10721067
//PERF_COUNT_SUB("get devices")
10731068
//fprintf(stderr, "[OD] Create kernel from binary\n");
1069+
const uint8_t *c_binary = &binary[0];
10741070
gpuInfo->mpArryPrograms[idx] = clCreateProgramWithBinary( gpuInfo->mpContext,numDevices,
1075-
mpArryDevsID, &length, (const unsigned char**) &binary,
1071+
mpArryDevsID, &length, &c_binary,
10761072
&binary_status, &clStatus );
10771073
CHECK_OPENCL( clStatus, "clCreateProgramWithBinary" );
10781074
//PERF_COUNT_SUB("clCreateProgramWithBinary")
1079-
free( binary );
10801075
free( mpArryDevsID );
10811076
mpArryDevsID = nullptr;
10821077
// PERF_COUNT_SUB("binaryExisted")

0 commit comments

Comments
 (0)