[RFC] Fixing dangling pointers caused by urCommandBufferRelease #1898
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some functions in the UR leaves dangling pointers, such as
commandBufferReleaseInternal
, which is called byurCommandBufferReleaseExp
. Coverity has detected that on intel/llvm, whenurCommandBufferReleaseExp
is called from the pi with tracing enabled, dangling pointers left byurCommandBufferReleaseExp
are used again here (specifically, thepi_ext_command_buffer
/ur_exp_command_buffer_handle_t
fed intoArgs
, which was already freed inurCommandBufferRelease
).The best course of action to fix this Coverity hit, to the best of my knowledge, is to fix the dangling pointers left by e.g.
urCommandBufferReleaseExp
. This PR contains a potential fix by taking references ofur_exp_command_buffer_handle_t
when callingurCommandBufferReleases
instead, and setting the pointers tonullptr
after they are deleted. This would allow code usingurCommandBufferReleaseExp
to actually catch that the command buffer has been freed.Unfortunately, this requires the API to be changed, as I've changed the function signature of
urCommandBufferReleaseExp
. I'm also aware that changing onlyurCommandBufferRelease
may result in asymmetry within the API. Thus, if this change was to be adopted, more functions may also have to be changed in a similar manner. Thus, I am opening this PR as an RFC to see what other people think of this, and to see if there are any potential issues with this approach.Additionally, if anyone has better ideas for fixing/handling this issue/Coverity hit without changing the UR API, please feel free to let me know. From what I can tell, this is the course of action that'll result in the least amount of problems in the future.
The respective draft DPC++ testing PR is here: intel/llvm#14782