summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2026-01-31 09:03:50 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2026-02-01 15:28:06 +0100
commit38aaabb059c6ad959e91bc74acbee03db06d70ce (patch)
treead7e1ddb1e49eab49862f344fad7df9b7a33fb4d /src/drivers
parentea18e097a7aa1ac6a330a35d97e518720d0ac5ad (diff)
Avoid leaving file descriptor open after failed call to mkstemp()
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx
index 3e45126b6..12c525c46 100644
--- a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx
+++ b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx
@@ -585,19 +585,18 @@ static int get_clipboard_image(struct wl_data_offer *offer) {
Fl_Shared_Image *shared = 0;
strcpy(tmp_fname, "/tmp/clipboardXXXXXX");
int fd = mkstemp(tmp_fname);
- if (fd == -1) return 1;
- while (true) {
- char buf[10000];
- ssize_t n = read(fds[0], buf, sizeof(buf));
- if (n <= 0) {
- close(fds[0]);
- close(fd);
- break;
+ if (fd >= 0) {
+ while (true) {
+ char buf[10000];
+ ssize_t n = read(fds[0], buf, sizeof(buf));
+ if (n <= 0) break;
+ n = write(fd, buf, n);
}
- n = write(fd, buf, n);
+ close(fd);
+ shared = Fl_Shared_Image::get(tmp_fname);
+ fl_unlink(tmp_fname);
}
- shared = Fl_Shared_Image::get(tmp_fname);
- fl_unlink(tmp_fname);
+ close(fds[0]);
if (!shared) return 1;
int ld = shared->ld() ? shared->ld() : shared->w() * shared->d();
uchar *rgb = new uchar[shared->w() * shared->h() * shared->d()];