From 12a601fffa066d6b67b85f3fb3962b8fc1074f06 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 30 Jun 2018 12:46:21 +0200 Subject: [PATCH] Fix CID 1393669 (Resource leak) Signed-off-by: Stefan Weil --- src/opencl/openclwrapper.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/opencl/openclwrapper.cpp b/src/opencl/openclwrapper.cpp index 44819bb8cb..33c1981dde 100644 --- a/src/opencl/openclwrapper.cpp +++ b/src/opencl/openclwrapper.cpp @@ -24,7 +24,6 @@ #if ON_APPLE #include -#include #endif #ifdef USE_OPENCL @@ -34,6 +33,7 @@ #include "errcode.h" // for ASSERT_HOST #include "opencl_device_selection.h" + GPUEnv OpenclDevice::gpuEnv; bool OpenclDevice::deviceIsSelected = false; @@ -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); @@ -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 binaries(numDevices); for ( i = 0; i < numDevices; i++ ) { @@ -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. */ @@ -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;