ui/vdagent: disconnect handlers and reset state on finalize
Avoid handlers being called with dangling pointers when the object is freed. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20210805135715.857938-10-marcandre.lureau@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
7424bfaa99
commit
5e0a24e868
17
ui/vdagent.c
17
ui/vdagent.c
@ -721,13 +721,8 @@ static void vdagent_chr_accept_input(Chardev *chr)
|
||||
vdagent_send_buf(vd);
|
||||
}
|
||||
|
||||
static void vdagent_chr_set_fe_open(struct Chardev *chr, int fe_open)
|
||||
static void vdagent_disconnect(VDAgentChardev *vd)
|
||||
{
|
||||
VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr);
|
||||
|
||||
if (!fe_open) {
|
||||
trace_vdagent_close();
|
||||
/* reset state */
|
||||
vdagent_reset_bufs(vd);
|
||||
vd->caps = 0;
|
||||
if (vd->mouse_hs) {
|
||||
@ -737,6 +732,15 @@ static void vdagent_chr_set_fe_open(struct Chardev *chr, int fe_open)
|
||||
qemu_clipboard_peer_unregister(&vd->cbpeer);
|
||||
memset(&vd->cbpeer, 0, sizeof(vd->cbpeer));
|
||||
}
|
||||
}
|
||||
|
||||
static void vdagent_chr_set_fe_open(struct Chardev *chr, int fe_open)
|
||||
{
|
||||
VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr);
|
||||
|
||||
if (!fe_open) {
|
||||
trace_vdagent_close();
|
||||
vdagent_disconnect(vd);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -781,6 +785,7 @@ static void vdagent_chr_fini(Object *obj)
|
||||
{
|
||||
VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(obj);
|
||||
|
||||
vdagent_disconnect(vd);
|
||||
buffer_free(&vd->outbuf);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user