Free clipboard data properly.

This commit is contained in:
Michael Jumper 2012-04-29 23:33:27 -07:00
parent 11303e0813
commit 71b1a2e0cc
4 changed files with 16 additions and 4 deletions

View File

@ -82,7 +82,7 @@ typedef struct rdp_guac_client_data {
guac_rdp_keysym_state_map keysym_state;
const char* clipboard;
char* clipboard;
} rdp_guac_client_data;

View File

@ -368,7 +368,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_client_data->rdp_inst = rdp_inst;
guac_client_data->mouse_button_mask = 0;
guac_client_data->current_surface = GUAC_DEFAULT_LAYER;
guac_client_data->clipboard = "";
guac_client_data->clipboard = NULL;
/* Clear keysym state mapping and keymap */
memset(guac_client_data->keysym_state, 0,

View File

@ -420,6 +420,9 @@ int rdp_guac_client_clipboard_handler(guac_client* client, char* data) {
RDP_EVENT_TYPE_CB_FORMAT_LIST,
NULL, NULL);
/* Free existing data */
free(((rdp_guac_client_data*) client->data)->clipboard);
/* Store data in client */
((rdp_guac_client_data*) client->data)->clipboard = strdup(data);

View File

@ -157,8 +157,14 @@ void guac_rdp_process_cb_data_request(guac_client* client,
NULL, NULL);
/* Set data and length */
data_response->data = (uint8*) strdup(clipboard);
data_response->size = strlen(clipboard) + 1;
if (clipboard != NULL) {
data_response->data = (uint8*) strdup(clipboard);
data_response->size = strlen(clipboard) + 1;
}
else {
data_response->data = (uint8*) strdup("");
data_response->size = 1;
}
/* Send response */
freerdp_channels_send_event(channels, (RDP_EVENT*) data_response);
@ -178,6 +184,9 @@ void guac_rdp_process_cb_data_response(guac_client* client,
/* Received clipboard data */
if (event->data[event->size - 1] == '\0') {
/* Free existing data */
free(((rdp_guac_client_data*) client->data)->clipboard);
/* Store clipboard data */
((rdp_guac_client_data*) client->data)->clipboard =
strdup((char*) event->data);