detached 44e253e

fix(server): mark bare resources gone after Destroy

commit
44e253e7b3442d90f34b034a4379113871345c09
author
brice · · 2026-09-29 04:55 UTC
parent
894fe61
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +7 -2
M server/args.go +3 -1
@@ -75,11 +75,13 @@ func (a Arg) NewID() uint32 { return uint32(a) }
7575 // Resource returns the object argument, nil for a null object. An object
7676 // libwayland created itself (wl_registry, wl_callback of wl_display) comes
7777 // back as a bare handle: Destroy works, it has no handler, version or client.
78+// Like other arguments, a bare handle is only valid during the dispatch; do
79+// not retain it.
7880 func (a Arg) Resource() *Resource {
7981 if r := live.resources[uintptr(a)]; r != nil || a == 0 {
8082 return r
8183 }
82- return &Resource{c: uintptr(a)}
84+ return &Resource{c: uintptr(a), bare: true}
8385 }
8486
8587 // Fd returns a received file descriptor. The handler owns it and must close it.
@@ -75,11 +75,13 @@ func (a Arg) NewID() uint32 { return uint32(a) }
75 // Resource returns the object argument, nil for a null object. An object75 // Resource returns the object argument, nil for a null object. An object
76 // libwayland created itself (wl_registry, wl_callback of wl_display) comes76 // libwayland created itself (wl_registry, wl_callback of wl_display) comes
77 // back as a bare handle: Destroy works, it has no handler, version or client.77 // back as a bare handle: Destroy works, it has no handler, version or client.
78+// Like other arguments, a bare handle is only valid during the dispatch; do
79+// not retain it.
78 func (a Arg) Resource() *Resource {80 func (a Arg) Resource() *Resource {
79 if r := live.resources[uintptr(a)]; r != nil || a == 0 {81 if r := live.resources[uintptr(a)]; r != nil || a == 0 {
80 return r82 return r
81 }83 }
82- return &Resource{c: uintptr(a)}84+ return &Resource{c: uintptr(a), bare: true}
83 }85 }
84 86
85 // Fd returns a received file descriptor. The handler owns it and must close it.87 // Fd returns a received file descriptor. The handler owns it and must close it.
M server/display.go +3 -0
@@ -32,6 +32,7 @@ type Resource struct {
3232 handler Handler
3333 OnDestroy func()
3434 gone bool
35+ bare bool // created by libwayland, no destroy callback
3536
3637 // Data holds the owner's state, typically the generated wrapper.
3738 Data any
@@ -286,6 +287,8 @@ func (r *Resource) Iface() *Interface { return r.iface }
286287 func (r *Resource) Destroy() {
287288 if !r.gone {
288289 wlResourceDestroy(r.c)
290+ // A bare handle gets no destroy callback to mark it gone.
291+ r.gone = r.gone || r.bare
289292 }
290293 }
291294
@@ -32,6 +32,7 @@ type Resource struct {
32 handler Handler32 handler Handler
33 OnDestroy func()33 OnDestroy func()
34 gone bool34 gone bool
35+ bare bool // created by libwayland, no destroy callback
35 36
36 // Data holds the owner's state, typically the generated wrapper.37 // Data holds the owner's state, typically the generated wrapper.
37 Data any38 Data any
@@ -286,6 +287,8 @@ func (r *Resource) Iface() *Interface { return r.iface }
286 func (r *Resource) Destroy() {287 func (r *Resource) Destroy() {
287 if !r.gone {288 if !r.gone {
288 wlResourceDestroy(r.c)289 wlResourceDestroy(r.c)
290+ // A bare handle gets no destroy callback to mark it gone.
291+ r.gone = r.gone || r.bare
289 }292 }
290 }293 }
291 294
M server/display_test.go +1 -1
@@ -44,7 +44,7 @@ func TestArgResourceUntracked(t *testing.T) {
4444 t.Fatal("null object is not nil")
4545 }
4646 r := Arg(0x1234).Resource()
47- if r == nil || r.c != 0x1234 || r.handler != nil {
47+ if r == nil || r.c != 0x1234 || r.handler != nil || !r.bare || !r.Alive() {
4848 t.Fatalf("untracked object %+v", r)
4949 }
5050 }
@@ -44,7 +44,7 @@ func TestArgResourceUntracked(t *testing.T) {
44 t.Fatal("null object is not nil")44 t.Fatal("null object is not nil")
45 }45 }
46 r := Arg(0x1234).Resource()46 r := Arg(0x1234).Resource()
47- if r == nil || r.c != 0x1234 || r.handler != nil {47+ if r == nil || r.c != 0x1234 || r.handler != nil || !r.bare || !r.Alive() {
48 t.Fatalf("untracked object %+v", r)48 t.Fatalf("untracked object %+v", r)
49 }49 }
50 }50 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 14

↑↓ moveenter openesc close