KhronosGroup / KhronosGroup/OpenCL-CTS

Memory leak in `negative_command_ndrange_kernel_with_different_context`

Open
#2,070 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
232
Forks
235
Avg merge
8d 7h
Merged PRs (30d)
18

Description

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; }

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with negative_command_ndrange_kernel_with_different_context and CreateKernelWithDifferentContext(), then inspect create_single_kernel_helper_create_program() and the related helpers in kernelHelpers.h. Review the interaction between kernelHelpers.h and typeWrappers.h, and run the named test to confirm the leak; done means the test no longer reports the memory leak without introducing cyclic header inclusion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.