NVIDIA / NVIDIA/cuda-python

BUG: API function calls do not cleanup correctly when a Python exception is thrown

Open
#1,641 0 comments 0 reactions 1 assignee View on GitHub

@mdboom is already working on this.

Since Aug 17, 2026.

  • #1669 by @mdboom — closed without merging
bug cuda.bindings P1
Dominant language
Cython
Stars
3.4k
Forks
329
Avg merge
1d 23h
Merged PRs (30d)
116

Description

In driver, runtime and nvrtc, function calls may not clean up correctly if a Python exception is thrown during Python-to-C argument conversion.

Some argument types require cleanup upon exiting the function. For example, a Python sequence is serialized into a heap-allocated C array that must be free'd before exiting the function. Once the C array is allocated, an exception thrown by the conversion of a subsequence argument will cause the array to never be freed.

Traditionally in C, one would use a goto label to handle cleanup in complex, multi-argument functions. Since we use Cython, we can instead use try/finally. If a major performance impact is measured of that, we may need to use a cleanup helper function (which could be called from all exit paths) instead.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.