summaryrefslogtreecommitdiffstats
path: root/platform/linuxbsd
diff options
context:
space:
mode:
authorRonald Casili <nvlled@gmail.com>2024-07-17 19:25:28 +0800
committerRémi Verschelde <rverschelde@gmail.com>2024-07-18 09:45:44 +0200
commit3636d9dafc4c4a9b80a94382a235172c80a083e8 (patch)
treece1fe28d1c6bb709115f443d3756929d718dffa8 /platform/linuxbsd
parentda4f6e439c0daec87d3f87f86b5b4592fca44fdb (diff)
downloadredot-engine-3636d9dafc4c4a9b80a94382a235172c80a083e8.tar.gz
Linux/X11: Fix memory leak from created screen images
Allocated XImages are improperly free'd with XFree. The X11 documentation says that XImage should use XDestroyImage to free both the image structure and the data pointed to by the image structure. Also fix a potential use-after-free bug.
Diffstat (limited to 'platform/linuxbsd')
-rw-r--r--platform/linuxbsd/x11/display_server_x11.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp
index edf3a40ccb..d6eb101a68 100644
--- a/platform/linuxbsd/x11/display_server_x11.cpp
+++ b/platform/linuxbsd/x11/display_server_x11.cpp
@@ -1519,7 +1519,7 @@ Color DisplayServerX11::screen_get_pixel(const Point2i &p_position) const {
if (image) {
XColor c;
c.pixel = XGetPixel(image, 0, 0);
- XFree(image);
+ XDestroyImage(image);
XQueryColor(x11_display, XDefaultColormap(x11_display, i), &c);
color = Color(float(c.red) / 65535.0, float(c.green) / 65535.0, float(c.blue) / 65535.0, 1.0);
break;
@@ -1637,11 +1637,12 @@ Ref<Image> DisplayServerX11::screen_get_image(int p_screen) const {
}
}
} else {
- XFree(image);
- ERR_FAIL_V_MSG(Ref<Image>(), vformat("XImage with RGB mask %x %x %x and depth %d is not supported.", (uint64_t)image->red_mask, (uint64_t)image->green_mask, (uint64_t)image->blue_mask, (int64_t)image->bits_per_pixel));
+ String msg = vformat("XImage with RGB mask %x %x %x and depth %d is not supported.", (uint64_t)image->red_mask, (uint64_t)image->green_mask, (uint64_t)image->blue_mask, (int64_t)image->bits_per_pixel);
+ XDestroyImage(image);
+ ERR_FAIL_V_MSG(Ref<Image>(), msg);
}
img = Image::create_from_data(width, height, false, Image::FORMAT_RGBA8, img_data);
- XFree(image);
+ XDestroyImage(image);
}
return img;