Skip to content

Fix potential leaks for interrupted dlpack capsule creation - #1291

Merged
leofang merged 1 commit into
NVIDIA:mainfrom
stiepan:fix_dlpack_capsule_cleanup_in_setup
Nov 30, 2025
Merged

Fix potential leaks for interrupted dlpack capsule creation#1291
leofang merged 1 commit into
NVIDIA:mainfrom
stiepan:fix_dlpack_capsule_cleanup_in_setup

Conversation

@stiepan

@stiepanstiepan commented Nov 27, 2025

Copy link
Copy Markdown
Member

Description

If dlpack's make_py_capsule is interrupted with an exception, it does not free memory malloced for the dl tensor and layout data.
This PR:

  • splits the make_py_capsule into a couple of different helpers (allocating the dlm tensor, layout setup, device setup, dtype setup) for readability
  • adjusts deleters so that they can be safely run with partially initialized object
  • adds a test that checks if the cleanup was run when exception is raised by checking the refcount of the buffer object. As the decref is not left to the deleter, this assures the deleter was run.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@copy-pr-bot

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@leofangleofang added bug Something isn't working P1 Medium priority - Should do cuda.core Everything related to the cuda.core module labels Nov 30, 2025
@leofangleofang added this to the cuda.core beta 10 milestone Nov 30, 2025
@leofang

Copy link
Copy Markdown
Member

/ok to test 044f179

@leofang
leofang enabled auto-merge (squash) November 30, 2025 02:09
@github-actions

This comment has been minimized.

@leofang
leofang merged commit ca74d6d into NVIDIA:mainNov 30, 2025
64 checks passed
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingcuda.coreEverything related to the cuda.core moduleP1Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@stiepan@leofang