mirror of
https://github.com/games-on-whales/gst-wayland-display.git
synced 2026-10-15 12:51:57 +00:00
[PR #36] [MERGED] fix(cuda): take own ref on GstCudaContext to fix double-unref at teardown #37
Labels
No labels
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
games-on-whales/gst-wayland-display#37
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/games-on-whales/gst-wayland-display/pull/36
Author: @salty2011
Created: 6/19/2026
Status: ✅ Merged
Merged: 8/19/2026
Merged by: @ABeltramo
Base:
stable← Head:fix/dmabuftocuda-context-teardown📝 Commits (1)
ce354c1fix(cuda): adopt the reference the gst_cuda helpers' short-circuit never transferred📊 Changes
1 file changed (+70 additions, -0 deletions)
View changed files
📝
wayland-display-core/src/utils/allocator/cuda/mod.rs(+70 -0)📄 Description
Problem
gst_cuda_ensure_element_context()andgst_cuda_handle_set_context()both open with:They report success while transferring nothing. Every other success path is
(transfer full)into the slot.CUDAContext::dropunconditionally unrefsself.ptr, so a wrapper built off that short-circuit destroys a reference it never owned.The compositor hits this on its own context:
new_from_gstreamer()calls the helper, which writes the slot then publishes the context.waylanddisplaysrc::set_context()synchronously, from inside the same call.None, so the inner, non-owning wrapper is stored and the outer one, holding the single legitimate reference, is dropped when the outer call returns.GstContext. At teardown that drops, the refcount hits zero, and theGstCudaContextis finalized while the pipeline's storedGstContextstill points at it.element->contextsand lands on freed memory: SIGSEGV ing_type_check_instance_is_fundamentally_a, at the end of every session teardown.Only bites when nothing else outlives the pipeline. A host that pins one
GstCudaContextfor the process lifetime keeps the refcount above zero and the defect stays invisible.Fix
adopt_slot_ref()takes a reference only on the short-circuit, at both constructors.Detection is unambiguous because both helpers write the slot only when it was NULL on entry: success with a non-NULL pre-value is necessarily the short-circuit, success with a NULL pre-value is necessarily a transfer. The
(transfer full)paths are untouched.What changed since this PR was opened
feat/nv12-outputtostable. That branch is divergent and unmerged; the defect is still present onstableat both constructors.gst_object_ref()beforegst_cuda_stream_new(). That fixes the SIGSEGV but adds a reference nothing removes on the normal transfer path, turning the crash into a per-sessionGstCudaContextleak. The conditional version is correct in both paths and is what has been running downstream.Not addressed here
The slot itself is never cleared when its context dies, so a later call can read a stale pre-value. That hazard predates this change and is unaffected by it. Happy to take it separately if you want it closed.
Verified
cargo fmtclean,cargo check --features cudaclean, 23 tests pass.CUDAContext::new()'s owngst_cuda_stream_newis unaffected (no slot, no short-circuit possible) and is untouched.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.