smithay icon indicating copy to clipboard operation
smithay copied to clipboard

Fix leaks of `SeatRc` and `KbdRc`, but using `Weak` in user data

Open ids1024 opened this issue 10 months ago • 4 comments

This fixes https://github.com/Smithay/smithay/issues/1422.

This can be tested by adding Drop impls that print to those two types, or using tools that detect leaks.

It's probably worth examining more to see why this created a cycle or otherwise didn't get freed, but if we don't anticipate issues, maybe it's best to use Weak in every possible place. I also need to look into some other reported leaks.

ids1024 avatar Feb 25 '25 21:02 ids1024

Updated now that calloop is released. LeakSanitizer in Anvil shows fewer leaks now.

ids1024 avatar Jul 30 '25 16:07 ids1024

Any particular reason why this only addresses the KeyboardHandle and not PointerHandle and TouchHandle as well?

Drakulix avatar Jul 30 '25 17:07 Drakulix

Good point.

Actually, that reference cycle may have been fixed a different way by https://github.com/Smithay/smithay/pull/1516 (I may do a bit more testing).

MemorySanitizer does show the calloop change addresses some leaks appearing there.

ids1024 avatar Jul 30 '25 17:07 ids1024

Ah, I see. So https://github.com/Smithay/smithay/pull/1516 changes known_kbds and the like to use wayland_server::Weak, while the change here uses a std::sync::Weak in KeyboardUserData and SeatUserData. Either prevents a leak, and both also works (using weak references for both doesn't cause early drops of anything since Wayland objects aren't destroyed on drop).

May be best to still make this change, as well as a similar change for pointer and touch. Avoiding strong references like this in user datas seems good in general.

ids1024 avatar Jul 31 '25 21:07 ids1024