Skip to content

Commit

Permalink
Fixed memory leak in xdpy_set_system_mouse_cursor()
Browse files Browse the repository at this point in the history
  • Loading branch information
Helodity authored and SiegeLord committed Dec 28, 2024
1 parent be2cb58 commit da53331
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/allegro5/internal/aintern_xdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct ALLEGRO_DISPLAY_XGLX
Cursor invisible_cursor;
Cursor current_cursor;
bool cursor_hidden;
bool is_system_cursor;

/* Icon for this window. */
Pixmap icon, icon_mask;
Expand Down
7 changes: 6 additions & 1 deletion src/x/xcursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void _al_xwin_destroy_mouse_cursor(ALLEGRO_MOUSE_CURSOR *cursor)
if (!glx->cursor_hidden)
XUndefineCursor(sysx->x11display, glx->window);
glx->current_cursor = None;
glx->is_system_cursor = true;
}
}

Expand All @@ -123,6 +124,7 @@ static bool xdpy_set_mouse_cursor(ALLEGRO_DISPLAY *display,
Window xwindow = glx->window;

glx->current_cursor = xcursor->cursor;
glx->is_system_cursor = false;

if (!glx->cursor_hidden) {
_al_mutex_lock(&system->lock);
Expand Down Expand Up @@ -204,8 +206,11 @@ static bool xdpy_set_system_mouse_cursor(ALLEGRO_DISPLAY *display,

_al_mutex_lock(&system->lock);

if (glx->is_system_cursor && glx->current_cursor) {
XFreeCursor(xdisplay, glx->current_cursor);
}
glx->current_cursor = XCreateFontCursor(xdisplay, cursor_shape);
/* XXX: leak? */
glx->is_system_cursor = true;

if (!glx->cursor_hidden) {
XDefineCursor(xdisplay, xwindow, glx->current_cursor);
Expand Down
1 change: 1 addition & 0 deletions src/x/xdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ static ALLEGRO_DISPLAY_XGLX *xdpy_create_display_locked(

d->invisible_cursor = None; /* Will be created on demand. */
d->current_cursor = None; /* Initially, we use the root cursor. */
d->is_system_cursor = true;
d->cursor_hidden = false;

d->icon = None;
Expand Down

0 comments on commit da53331

Please sign in to comment.