From 058acae43f12d046b9c5bb70be4cc38b42837334 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 13 Feb 2013 23:46:06 +0000 Subject: Fix potential double free when we've had something in our clipboard, another app has claimed the clipboard, and the clipboard is now empty/disowned by all apps, and we try to paste the empty clipboard twice in NetSurf. --- riscos/textselection.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/riscos/textselection.c b/riscos/textselection.c index 0cb8eb2c0..7e248938e 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -285,6 +285,7 @@ void gui_get_clipboard(char **buffer, size_t *length) void ro_gui_discard_clipboard_contents(void) { free(clipboard); + clipboard = NULL; clip_length = 0; } @@ -418,18 +419,20 @@ bool ro_gui_selection_prepare_paste_dataload( size = ftell(fp); fseek(fp, 0, SEEK_SET); - local_cb = malloc(size); - if (local_cb != NULL) { - fread(local_cb, 1, size, fp); + if (size > 0) { + local_cb = malloc(size); + if (local_cb != NULL) { + fread(local_cb, 1, size, fp); - fclose(fp); - - ret = utf8_from_local_encoding(local_cb, size, - &clipboard); - if (ret == UTF8_CONVERT_OK) { - clip_length = strlen(clipboard); + ret = utf8_from_local_encoding(local_cb, size, + &clipboard); + if (ret == UTF8_CONVERT_OK) { + clip_length = strlen(clipboard); + } } } + + fclose(fp); } /* Send DataLoadAck */ -- cgit v1.2.3