mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
cursor: Properly check realloc for errors
Do not override realloc's input pointer before checking for errors, otherwise it's not possible to keep old value, as intended. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
This commit is contained in:
parent
2978fd701a
commit
0de833da29
1 changed files with 7 additions and 6 deletions
|
|
@ -351,6 +351,8 @@ load_callback(struct xcursor_images *images, void *data)
|
||||||
{
|
{
|
||||||
struct wl_cursor_theme *theme = data;
|
struct wl_cursor_theme *theme = data;
|
||||||
struct wl_cursor *cursor;
|
struct wl_cursor *cursor;
|
||||||
|
struct wl_cursor **p;
|
||||||
|
size_t s;
|
||||||
|
|
||||||
if (wl_cursor_theme_get_cursor(theme, images->name)) {
|
if (wl_cursor_theme_get_cursor(theme, images->name)) {
|
||||||
xcursor_images_destroy(images);
|
xcursor_images_destroy(images);
|
||||||
|
|
@ -360,15 +362,14 @@ load_callback(struct xcursor_images *images, void *data)
|
||||||
cursor = wl_cursor_create_from_xcursor_images(images, theme);
|
cursor = wl_cursor_create_from_xcursor_images(images, theme);
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
theme->cursor_count++;
|
s = theme->cursor_count + 1;
|
||||||
theme->cursors =
|
p = realloc(theme->cursors, s * sizeof theme->cursors[0]);
|
||||||
realloc(theme->cursors,
|
|
||||||
theme->cursor_count * sizeof theme->cursors[0]);
|
|
||||||
|
|
||||||
if (theme->cursors == NULL) {
|
if (p == NULL) {
|
||||||
theme->cursor_count--;
|
|
||||||
free(cursor);
|
free(cursor);
|
||||||
} else {
|
} else {
|
||||||
|
theme->cursor_count = s;
|
||||||
|
theme->cursors = p;
|
||||||
theme->cursors[theme->cursor_count - 1] = cursor;
|
theme->cursors[theme->cursor_count - 1] = cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue