diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-09-17 02:42:40 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-09-19 17:03:22 +0200 |
commit | 4f65f4333b5f38ff08d24d71766f7d27849b81a4 (patch) | |
tree | af0974710797dcb62da9824e6efddb8ccd1d8d3f /sc/source | |
parent | 4b320031ad05ecc24b6aa6ef7cf9904075c610d7 (diff) |
fix a number of memory leaks
Change-Id: I1e81558d0f087c1629006b757b1efb332108d5f1
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/opencl/openclwrapper.cxx | 63 |
1 files changed, 13 insertions, 50 deletions
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx index 8c4ed8f7c44d..c88dcb8342cc 100644 --- a/sc/source/core/opencl/openclwrapper.cxx +++ b/sc/source/core/opencl/openclwrapper.cxx @@ -255,50 +255,34 @@ int OpenclDevice::writeBinaryToFile( const char* fileName, const char* birary, s int OpenclDevice::generatBinFromKernelSource( cl_program program, const char * clFileName ) { - unsigned int i = 0; - cl_int clStatus; - size_t *binarySizes; cl_uint numDevices; - cl_device_id *mpArryDevsID; - char **binaries, *str = NULL; + char *str = NULL; - clStatus = clGetProgramInfo( program, CL_PROGRAM_NUM_DEVICES, + cl_int clStatus = clGetProgramInfo( program, CL_PROGRAM_NUM_DEVICES, sizeof(numDevices), &numDevices, NULL ); CHECK_OPENCL( clStatus, "clGetProgramInfo" ); - mpArryDevsID = (cl_device_id*) malloc( sizeof(cl_device_id) * numDevices ); - if ( mpArryDevsID == NULL ) - { - return 0; - } + std::vector<cl_device_id> mpArryDevsID(numDevices); /* grab the handles to all of the devices in the program. */ clStatus = clGetProgramInfo( program, CL_PROGRAM_DEVICES, - sizeof(cl_device_id) * numDevices, mpArryDevsID, NULL ); + sizeof(cl_device_id) * numDevices, &mpArryDevsID[0], NULL ); CHECK_OPENCL( clStatus, "clGetProgramInfo" ); /* figure out the sizes of each of the binaries. */ - binarySizes = (size_t*) malloc( sizeof(size_t) * numDevices ); + std::vector<size_t> binarySizes(numDevices); clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARY_SIZES, - sizeof(size_t) * numDevices, binarySizes, NULL ); + sizeof(size_t) * numDevices, &binarySizes[0], NULL ); CHECK_OPENCL( clStatus, "clGetProgramInfo" ); /* copy over all of the generated binaries. */ - binaries = (char**) malloc( sizeof(char *) * numDevices ); - if ( binaries == NULL ) - { - return 0; - } + boost::scoped_array<char*> binaries(new char*[numDevices]); - for ( i = 0; i < numDevices; i++ ) + for ( size_t i = 0; i < numDevices; i++ ) { if ( binarySizes[i] != 0 ) { - binaries[i] = (char*) malloc( sizeof(char) * binarySizes[i] ); - if ( binaries[i] == NULL ) - { - return 0; - } + binaries[i] = new char[binarySizes[i]]; } else { @@ -307,11 +291,11 @@ int OpenclDevice::generatBinFromKernelSource( cl_program program, const char * c } clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARIES, - sizeof(char *) * numDevices, binaries, NULL ); + sizeof(char *) * numDevices, binaries.get(), NULL ); CHECK_OPENCL(clStatus,"clGetProgramInfo"); /* dump out each binary into its own separate file. */ - for ( i = 0; i < numDevices; i++ ) + for ( size_t i = 0; i < numDevices; i++ ) { char fileName[256] = { 0 }, cl_name[128] = { 0 }; @@ -337,32 +321,11 @@ int OpenclDevice::generatBinFromKernelSource( cl_program program, const char * c } // Release all resouces and memory - for ( i = 0; i < numDevices; i++ ) - { - if ( binaries[i] != NULL ) - { - free( binaries[i] ); - binaries[i] = NULL; - } - } - - if ( binaries != NULL ) + for ( size_t i = 0; i < numDevices; i++ ) { - free( binaries ); - binaries = NULL; + delete[] binaries[i]; } - if ( binarySizes != NULL ) - { - free( binarySizes ); - binarySizes = NULL; - } - - if ( mpArryDevsID != NULL ) - { - free( mpArryDevsID ); - mpArryDevsID = NULL; - } return 1; } |