Skip to content

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

Open

Description

@mdboom

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.

Activity

  1. added
    bugSomething isn't working
    cuda.bindingsEverything related to the cuda.bindings module
    on Feb 18, 2026
  2. added this to the cuda.bindings next milestone on Feb 18, 2026
  3. self-assigned this
    on Feb 20, 2026
  4. added a commit that references this issue on Feb 20, 2026
    6793639
  5. added
    P0High priority - Must do!
    and removed
    triageNeeds the team's attention
    on May 11, 2026
  6. removed their assignment
    on May 19, 2026
  7. added theissue type on Jun 24, 2026
  8. added
    P1Medium priority - Should do
    and removed
    P0High priority - Must do!
    on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should dobugSomething isn't workingcuda.bindingsEverything related to the cuda.bindings module

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions