manuelnOOb wrote
I know where leaking is from (in initGpu), but I cannot figure out why this happens.
I mean, exactly which OpenCL function returns CL_OUT_OF_RESOURCES? Your initGpu() function calls seven or so different OpenCL functions, and each one could have a different reason for failing. You need to individually check the return codes for *every* OpenCL function or it'll be impossible to find out what's going wrong.