Memory leak in `negative_command_ndrange_kernel_with_different_context`
In the struct CommandNDRangeKernelKernelWithDifferentContext, the method CreateKernelWithDifferentContext() uses a helper function, create_single_kernel_helper_create_program(), which calls another helper. Every helper takes a cl_program * as an argument, but the program variable being used is actually a clProgramWrapper.
I think this is the cause of the memory leak. Indeed replacing the call to create_single_kernel_helper_create_program() with a direct call to clCreateProgramWithSource() solves the issue.
Changing the helpers to accept wrapper arguments is more than a trivial change because this will eventually require kernelHelpers.h to include typeWrappers.h but that causes cyclic inclusion with the headers as they currently are.
The relevant method in the wrapper class acknowledges it is not ideal to be doing things this way:
// Ideally this function should not exist as it breaks encapsulation by // allowing external mutation of the Wrapper internal state. However, too // much code currently relies on this. For example, instead of using T* as // output parameters, existing code can be updated to use Wrapper& instead. T *operator&() { return &object; }