diff --git a/opencl/openclwrapper.cpp b/opencl/openclwrapper.cpp index 150f2567..7c148d3c 100644 --- a/opencl/openclwrapper.cpp +++ b/opencl/openclwrapper.cpp @@ -711,6 +711,14 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c binaries[i] = (char*) malloc( sizeof(char) * binarySizes[i] ); if ( binaries[i] == NULL ) { + // cleanup all memory allocated so far + for(int cleanupIndex = 0; cleanupIndex < i; ++cleanupIndex) + { + free(binaries[cleanupIndex]); + } + // cleanup binary array + free(binaries); + return 0; } }