summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-05-03 14:28:45 +0000
committerManolo Gouy <Manolo>2016-05-03 14:28:45 +0000
commitd47b431750f545a2066e6d4a07e69b5088a7396f (patch)
tree60638712839992fc346a7d6c28b2b2b69cb7173d /src
parent86a7bbe93a5743d548af8c92fbbbf0a7518d0578 (diff)
Fix potential memory leak under X11 when pasted image is not accepted by the receiving app.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11709 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_x.cxx17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index 92b9be5fc..64980ca11 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -1365,9 +1365,9 @@ fprintf(stderr,"\n");*/
sn_buffer[bytesread] = 0;
convert_crlf(sn_buffer, bytesread);
}
+ if (!fl_selection_requestor) return 0;
if (Fl::e_clipboard_type == Fl::clipboard_image) {
if (bytesread == 0) return 0;
- Fl_Image *image = 0;
static char tmp_fname[21];
static Fl_Shared_Image *shared = 0;
strcpy(tmp_fname, "/tmp/clipboardXXXXXX");
@@ -1383,18 +1383,23 @@ fprintf(stderr,"\n");*/
shared = Fl_Shared_Image::get(tmp_fname);
unlink(tmp_fname);
if (!shared) return 0;
- image = shared->copy();
+ uchar *rgb = new uchar[shared->w() * shared->h() * shared->d()];
+ memcpy(rgb, shared->data()[0], shared->w() * shared->h() * shared->d());
+ Fl_RGB_Image *image = new Fl_RGB_Image(rgb, shared->w(), shared->h(), shared->d());
shared->release();
+ image->alloc_array = 1;
Fl::e_clipboard_data = (void*)image;
}
- if (!fl_selection_requestor) return 0;
-
- if (Fl::e_clipboard_type == Fl::clipboard_plain_text) {
+ else if (Fl::e_clipboard_type == Fl::clipboard_plain_text) {
Fl::e_text = sn_buffer ? (char*)sn_buffer : (char *)"";
Fl::e_length = bytesread;
}
int old_event = Fl::e_number;
- fl_selection_requestor->handle(Fl::e_number = FL_PASTE);
+ int retval = fl_selection_requestor->handle(Fl::e_number = FL_PASTE);
+ if (!retval && Fl::e_clipboard_type == Fl::clipboard_image) {
+ delete (Fl_RGB_Image*)Fl::e_clipboard_data;
+ Fl::e_clipboard_data= NULL;
+ }
Fl::e_number = old_event;
// Detect if this paste is due to Xdnd by the property name (I use
// XA_SECONDARY for that) and send an XdndFinished message. It is not