summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-02-13 23:46:06 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-02-13 23:46:06 +0000
commit058acae43f12d046b9c5bb70be4cc38b42837334 (patch)
treed757caa3c500afa2fe2091a49eb3cafe17decec2 /riscos
parent58540d83d8bd106edf354db815685cab0a17421d (diff)
downloadnetsurf-058acae43f12d046b9c5bb70be4cc38b42837334.tar.gz
netsurf-058acae43f12d046b9c5bb70be4cc38b42837334.tar.bz2
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.
Diffstat (limited to 'riscos')
-rw-r--r--riscos/textselection.c21
1 files 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 */