diff options
author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2018-05-28 12:49:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-28 12:49:34 +0200 |
commit | daa136784d69c224fa60161a8f9d5494e56e9ced (patch) | |
tree | 320168e7c3608069157adb4ef9538ab802cf6c2e /platform | |
parent | bce002f5c3555080cc9edec7fa6650c9f072e632 (diff) | |
parent | aa174d963df943ba8a763a57a51888e3a37c2fe0 (diff) |
Merge pull request #19181 from guilhermefelipecgs/fix_memory_leak
Fix memory leak in set_custom_mouse_cursor
Diffstat (limited to 'platform')
-rw-r--r-- | platform/osx/os_osx.mm | 10 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 7 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 5 |
3 files changed, 17 insertions, 5 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 5589f93a5d..404ee5f476 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1546,7 +1546,7 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c image = texture->get_data(); - NSBitmapImageRep *imgrep = [[[NSBitmapImageRep alloc] + NSBitmapImageRep *imgrep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:int(texture_size.width) pixelsHigh:int(texture_size.height) @@ -1556,7 +1556,7 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:int(texture_size.width) * 4 - bitsPerPixel:32] autorelease]; + bitsPerPixel:32]; ERR_FAIL_COND(imgrep == nil); uint8_t *pixels = [imgrep bitmapData]; @@ -1588,16 +1588,20 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c image->unlock(); - NSImage *nsimage = [[[NSImage alloc] initWithSize:NSMakeSize(texture_size.width, texture_size.height)] autorelease]; + NSImage *nsimage = [[NSImage alloc] initWithSize:NSMakeSize(texture_size.width, texture_size.height)]; [nsimage addRepresentation:imgrep]; NSCursor *cursor = [[NSCursor alloc] initWithImage:nsimage hotSpot:NSMakePoint(p_hotspot.x, p_hotspot.y)]; + [cursors[p_shape] release]; cursors[p_shape] = cursor; if (p_shape == CURSOR_ARROW) { [cursor set]; } + + [imgrep release]; + [nsimage release]; } else { // Reset to default system cursor cursors[p_shape] = NULL; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 8d664b5832..af03432838 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2081,7 +2081,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap UINT size = sizeof(UINT) * image_size; // Create the BITMAP with alpha channel - COLORREF *buffer = (COLORREF *)malloc(sizeof(COLORREF) * image_size); + COLORREF *buffer = (COLORREF *)memalloc(sizeof(COLORREF) * image_size); image->lock(); for (UINT index = 0; index < image_size; index++) { @@ -2108,6 +2108,8 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap GetMaskBitmaps(bitmap, clrTransparent, hAndMask, hXorMask); if (NULL == hAndMask || NULL == hXorMask) { + memfree(buffer); + DeleteObject(bitmap); return; } @@ -2132,6 +2134,9 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap if (hXorMask != NULL) { DeleteObject(hXorMask); } + + memfree(buffer); + DeleteObject(bitmap); } else { // Reset to default system cursor cursors[p_shape] = NULL; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 7b514d0f90..efa55ddf58 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -2463,7 +2463,7 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c cursor_image->yhot = p_hotspot.y; // allocate memory to contain the whole file - cursor_image->pixels = (XcursorPixel *)malloc(size); + cursor_image->pixels = (XcursorPixel *)memalloc(size); image->lock(); @@ -2489,6 +2489,9 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c if (p_shape == CURSOR_ARROW) { XDefineCursor(x11_display, x11_window, cursors[p_shape]); } + + memfree(cursor_image->pixels); + XcursorImageDestroy(cursor_image); } else { // Reset to default system cursor if (img[p_shape]) { |