summaryrefslogtreecommitdiff
path: root/src/drivers/X11/Fl_X11_Screen_Driver.cxx
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-11-02 13:13:41 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-11-02 13:13:53 +0100
commit98a4e492040f9c5284e8f39276f1d559f6d5adce (patch)
tree12ce7257c49cca4ff08276f19265c2b33b815f9e /src/drivers/X11/Fl_X11_Screen_Driver.cxx
parentf0af606708a5ede2bb99880c9ffb68f29a2439c0 (diff)
Fix possible memory leak in Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled()
Thanks to "fire-eggs" for spotting it. Also minor optimisations in Fl_X11_Screen_Driver::read_win_rectangle_unscaled() and Fl_Cocoa_Screen_Driver::read_win_rectangle_unscaled(). This closes PR #151.
Diffstat (limited to 'src/drivers/X11/Fl_X11_Screen_Driver.cxx')
-rw-r--r--src/drivers/X11/Fl_X11_Screen_Driver.cxx8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
index 30482cf8f..914104769 100644
--- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
@@ -750,7 +750,6 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
XImage *image; // Captured image
int i, maxindex; // Looping vars
int x, y; // Current X & Y in image
- int d; // Depth of image
unsigned char *line, // Array to hold image row
*line_ptr; // Pointer to current line image
unsigned char *pixel; // Current color value
@@ -865,11 +864,10 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
printf("map_entries = %d\n", fl_visual->visual->map_entries);
#endif // DEBUG
- d = 3;
+ const int d = 3; // Depth of image
uchar *p = NULL;
// Allocate the image data array as needed...
- const uchar *oldp = p;
- if (!p) p = new uchar[w * h * d];
+ p = new uchar[w * h * d];
// Initialize the default colors/alpha in the whole image...
memset(p, 0, w * h * d);
@@ -1167,7 +1165,7 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
XDestroyImage(image);
Fl_RGB_Image *rgb = new Fl_RGB_Image(p, w, h, d);
- if (!oldp) rgb->alloc_array = 1;
+ rgb->alloc_array = 1;
return rgb;
}