It's unnecessary to keep guest_peer_count since that can be recomputed reasonably quickly by walking the notifier list.
Signed-off-by: Lukasz Kornicki <[email protected]> --- ui/clipboard.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/ui/clipboard.c b/ui/clipboard.c index f750b494eb..3f6c259124 100644 --- a/ui/clipboard.c +++ b/ui/clipboard.c @@ -12,8 +12,6 @@ static VMChangeStateEntry *cb_change_state_entry = NULL; static bool cb_reset_serial_on_resume = false; -static int guest_peer_count; - static const VMStateDescription vmstate_cbcontent = { .name = "clipboard/content", .version_id = 0, @@ -82,10 +80,6 @@ void qemu_clipboard_peer_register(QemuClipboardPeer *peer) cb_change_state_entry = qemu_add_vm_change_state_handler(qemu_clipboard_change_state, NULL); } - if (peer->guest) { - guest_peer_count++; - } - notifier_list_add(&clipboard_notifiers, &peer->notifier); qemu_clipboard_notify_peer_update(peer, true); } @@ -98,12 +92,6 @@ void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer) qemu_clipboard_peer_release(peer, i); } notifier_remove(&peer->notifier); - - if (peer->guest) { - assert(guest_peer_count > 0); - guest_peer_count--; - } - qemu_clipboard_notify_peer_update(peer, false); if (QLIST_EMPTY(&clipboard_notifiers.notifiers)) { @@ -114,7 +102,17 @@ void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer) bool qemu_clipboard_guest_peer_present(void) { - return guest_peer_count > 0; + Notifier *n; + + QLIST_FOREACH(n, &clipboard_notifiers.notifiers, node) { + QemuClipboardPeer *peer = container_of(n, QemuClipboardPeer, notifier); + + if (peer->guest) { + return true; + } + } + + return false; } bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer, -- 2.43.0
