Fix leaks of `SeatRc` and `KbdRc`, but using `Weak` in user data
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.
Updated now that calloop is released. LeakSanitizer in Anvil shows fewer leaks now.
Any particular reason why this only addresses the KeyboardHandle and not PointerHandle and TouchHandle as well?
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.
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.