Skip to content

Commit

Permalink
Fix CID 1393669 (Resource leak)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jun 30, 2018
1 parent 1de55c8 commit 12a601f
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#if ON_APPLE
#include <mach/mach_time.h>
#include <cstdio>
#endif

#ifdef USE_OPENCL
Expand All @@ -34,6 +33,7 @@

#include "errcode.h" // for ASSERT_HOST
#include "opencl_device_selection.h"

GPUEnv OpenclDevice::gpuEnv;

bool OpenclDevice::deviceIsSelected = false;
Expand Down Expand Up @@ -915,7 +915,7 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c
size_t *binarySizes;
cl_uint numDevices;
cl_device_id *mpArryDevsID;
char **binaries, *str = nullptr;
char *str = nullptr;

clStatus = clGetProgramInfo(program, CL_PROGRAM_NUM_DEVICES,
sizeof(numDevices), &numDevices, nullptr);
Expand All @@ -940,10 +940,7 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c
CHECK_OPENCL( clStatus, "clGetProgramInfo" );

/* copy over all of the generated binaries. */
binaries = (char**) malloc( sizeof(char *) * numDevices );
if (binaries == nullptr) {
return 0;
}
std::vector<char*> binaries(numDevices);

for ( i = 0; i < numDevices; i++ )
{
Expand All @@ -961,7 +958,8 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c
}

clStatus = clGetProgramInfo(program, CL_PROGRAM_BINARIES,
sizeof(char *) * numDevices, binaries, nullptr);
sizeof(char *) * numDevices,
&binaries[0], nullptr);
CHECK_OPENCL(clStatus,"clGetProgramInfo");

/* dump out each binary into its own separate file. */
Expand Down Expand Up @@ -994,12 +992,8 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c
for ( i = 0; i < numDevices; i++ )
{
free(binaries[i]);
binaries[i] = nullptr;
}

free(binaries);
binaries = nullptr;

free(binarySizes);
binarySizes = nullptr;

Expand Down

0 comments on commit 12a601f

Please sign in to comment.