diff options
author | Hans de Goede <hdegoede@redhat.com> | 2011-03-26 17:12:02 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2011-03-28 09:27:46 +0200 |
commit | e7ba55789ccf61d22c76662b08648160a742aa88 (patch) | |
tree | 93f216fc7467e19d6d8353a772b8cc680e9475af | |
parent | 2d2ff49500d79e97228c8c8943ab4899e851187f (diff) |
udscs: Let the read call back take owner ship of the data
This avoids the need to do a memcpy if the read callback wants to keep
the data around. This makes the read callback responsible for freeing the
buffer.
-rw-r--r-- | udscs.c | 1 | ||||
-rw-r--r-- | udscs.h | 2 | ||||
-rw-r--r-- | vdagent-x11.c | 5 | ||||
-rw-r--r-- | vdagent-x11.h | 2 | ||||
-rw-r--r-- | vdagent.c | 9 | ||||
-rw-r--r-- | vdagentd.c | 3 |
6 files changed, 16 insertions, 6 deletions
@@ -466,7 +466,6 @@ static void udscs_read_complete(struct udscs_connection **connp) return; } - free(conn->data.buf); conn->header_read = 0; memset(&conn->data, 0, sizeof(conn->data)); } @@ -42,7 +42,7 @@ typedef void (*udscs_connect_callback)(struct udscs_connection *conn); received. The callback may call udscs_destroy_connection, in which case *connp must be made NULL (which udscs_destroy_connection takes care of) */ typedef void (*udscs_read_callback)(struct udscs_connection **connp, - struct udscs_message_header *header, const uint8_t *data); + struct udscs_message_header *header, uint8_t *data); /* Callback type for udscs_server_for_all_clients. Clients can be disconnected from this callback just like with a read callback. */ typedef int (*udscs_for_all_clients_callback)(struct udscs_connection **connp, diff --git a/vdagent-x11.c b/vdagent-x11.c index 5febe71..fd4d1ec 100644 --- a/vdagent-x11.c +++ b/vdagent-x11.c @@ -905,7 +905,7 @@ void vdagent_x11_clipboard_grab(struct vdagent_x11 *x11, uint32_t *types, } void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint32_t type, - const uint8_t *data, uint32_t size) + uint8_t *data, uint32_t size) { Atom prop; XEvent *event; @@ -914,6 +914,7 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint32_t type, if (!x11->selection_request) { fprintf(x11->errfile, "received clipboard data without an outstanding" "selection request, ignoring\n"); + free(data); return; } @@ -924,6 +925,7 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint32_t type, fprintf(x11->errfile, "expecting type %u clipboard data got %u\n", type_from_event, type); vdagent_x11_send_selection_notify(x11, None, 1); + free(data); return; } @@ -936,6 +938,7 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint32_t type, event->xselectionrequest.target, 8, PropModeReplace, data, size); vdagent_x11_send_selection_notify(x11, prop, 1); + free(data); } void vdagent_x11_clipboard_release(struct vdagent_x11 *x11) diff --git a/vdagent-x11.h b/vdagent-x11.h index 55baf82..10f27ee 100644 --- a/vdagent-x11.h +++ b/vdagent-x11.h @@ -41,7 +41,7 @@ void vdagent_x11_clipboard_grab(struct vdagent_x11 *x11, uint32_t *types, uint32_t type_count); void vdagent_x11_clipboard_request(struct vdagent_x11 *x11, uint32_t type); void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint32_t type, - const uint8_t *data, uint32_t size); + uint8_t *data, uint32_t size); void vdagent_x11_clipboard_release(struct vdagent_x11 *x11); #endif @@ -42,29 +42,36 @@ static FILE *logfile = NULL; static int quit = 0; void daemon_read_complete(struct udscs_connection **connp, - struct udscs_message_header *header, const uint8_t *data) + struct udscs_message_header *header, uint8_t *data) { switch (header->type) { case VDAGENTD_MONITORS_CONFIG: vdagent_x11_set_monitor_config(x11, (VDAgentMonitorsConfig *)data); + free(data); break; case VDAGENTD_CLIPBOARD_REQUEST: vdagent_x11_clipboard_request(x11, header->opaque); + free(data); break; case VDAGENTD_CLIPBOARD_GRAB: vdagent_x11_clipboard_grab(x11, (uint32_t *)data, header->size / sizeof(uint32_t)); + free(data); break; case VDAGENTD_CLIPBOARD_DATA: vdagent_x11_clipboard_data(x11, header->opaque, data, header->size); + /* vdagent_x11_clipboard_data takes ownership of the data (or frees + it immediately) */ break; case VDAGENTD_CLIPBOARD_RELEASE: vdagent_x11_clipboard_release(x11); + free(data); break; default: if (verbose) fprintf(logfile, "Unknown message from vdagentd type: %d\n", header->type); + free(data); } } @@ -466,7 +466,7 @@ void agent_disconnect(struct udscs_connection *conn) } void agent_read_complete(struct udscs_connection **connp, - struct udscs_message_header *header, const uint8_t *data) + struct udscs_message_header *header, uint8_t *data) { struct agent_data *agent_data = udscs_get_user_data(*connp); @@ -497,6 +497,7 @@ void agent_read_complete(struct udscs_connection **connp, fprintf(logfile, "unknown message from vdagent: %u, ignoring\n", header->type); } + free(data); } /* main */ |