diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-01-18 10:00:12 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-01-18 10:00:12 +0100 |
commit | f269ec359e0a9f7c11659af9e8121f7e8e714060 (patch) | |
tree | 4bf3c0c15d2a4304e3c002f1025ff0aac9c22831 | |
parent | 5c2de0012f3ce30fe958b05db0549dbd37d4bb6d (diff) |
vdagent-x11: Fix crash on vdagend restart (rhbz#894365)
vdagent_x11_destroy() cleans up clipboard state and will tell the client
it is releasing the clipboard if it owns it. But when the vdagentd is
restarted the unix socket is disconnected and x11->vdagentd points to
already free-ed memory, leading to a crash.
This patch fixes this by not trying to send messages to the client on
cleanup when the unix socket is disconnected.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | src/vdagent-x11.c | 12 | ||||
-rw-r--r-- | src/vdagent-x11.h | 2 | ||||
-rw-r--r-- | src/vdagent.c | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/src/vdagent-x11.c b/src/vdagent-x11.c index 380182a..1fd36df 100644 --- a/src/vdagent-x11.c +++ b/src/vdagent-x11.c @@ -169,13 +169,16 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd, return x11; } -void vdagent_x11_destroy(struct vdagent_x11 *x11) +void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected) { uint8_t sel; if (!x11) return; + if (vdagentd_disconnected) + x11->vdagentd = NULL; + for (sel = 0; sel < VD_AGENT_CLIPBOARD_SELECTION_SECONDARY; ++sel) { vdagent_x11_set_clipboard_owner(x11, sel, owner_none); } @@ -254,8 +257,9 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11, "ownership change, clearing"); once = 0; } - udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_DATA, selection, - VD_AGENT_CLIPBOARD_NONE, NULL, 0); + if (x11->vdagentd) + udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_DATA, selection, + VD_AGENT_CLIPBOARD_NONE, NULL, 0); if (curr_conv == x11->conversion_req) { x11->conversion_req = next_conv; x11->clipboard_data_size = 0; @@ -272,7 +276,7 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11, if (new_owner == owner_none) { /* When going from owner_guest to owner_none we need to send a clipboard release message to the client */ - if (x11->clipboard_owner[selection] == owner_guest) { + if (x11->clipboard_owner[selection] == owner_guest && x11->vdagentd) { udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_RELEASE, selection, 0, NULL, 0); } diff --git a/src/vdagent-x11.h b/src/vdagent-x11.h index e856470..9e61508 100644 --- a/src/vdagent-x11.h +++ b/src/vdagent-x11.h @@ -30,7 +30,7 @@ struct vdagent_x11; struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd, int debug, int sync); -void vdagent_x11_destroy(struct vdagent_x11 *x11); +void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected); int vdagent_x11_get_fd(struct vdagent_x11 *x11); void vdagent_x11_do_read(struct vdagent_x11 *x11); diff --git a/src/vdagent.c b/src/vdagent.c index 0af82b1..e2ceddd 100644 --- a/src/vdagent.c +++ b/src/vdagent.c @@ -239,7 +239,7 @@ reconnect: udscs_client_handle_fds(&client, &readfds, &writefds); } - vdagent_x11_destroy(x11); + vdagent_x11_destroy(x11, client == NULL); udscs_destroy_connection(&client); if (!quit) goto reconnect; |