[Commits] SDL: Wayland: Fixed crash if allocating memory for cursor failed.

libsdl.org revision control commits-owner at libsdl.org
Wed Mar 2 11:32:29 PST 2016


details:   https://hg.libsdl.org/SDL/rev/91b34fbbb88e
changeset: 10098:91b34fbbb88e
user:      Philipp Wiesemann <philipp.wiesemann at arcor.de>
date:      Wed Mar 02 20:25:09 2016 +0100
description:
Wayland: Fixed crash if allocating memory for cursor failed.

Also added missing error message if first allocation failed.

diffstat:

 src/video/wayland/SDL_waylandmouse.c |  12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diffs (36 lines):

diff -r 06085b9c73ef -r 91b34fbbb88e src/video/wayland/SDL_waylandmouse.c
--- a/src/video/wayland/SDL_waylandmouse.c	Wed Mar 02 20:24:43 2016 +0100
+++ b/src/video/wayland/SDL_waylandmouse.c	Wed Mar 02 20:25:09 2016 +0100
@@ -159,6 +159,11 @@
         SDL_VideoDevice *vd = SDL_GetVideoDevice ();
         SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata;
         Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
+        if (!data) {
+            SDL_OutOfMemory();
+            free(cursor);
+            return NULL;
+        }
         cursor->driverdata = (void *) data;
 
         /* Assume ARGB8888 */
@@ -187,6 +192,8 @@
         data->hot_y = hot_y;
         data->w = surface->w;
         data->h = surface->h;
+    } else {
+        SDL_OutOfMemory();
     }
 
     return cursor;
@@ -200,6 +207,11 @@
     cursor = calloc(1, sizeof (*cursor));
     if (cursor) {
         Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
+        if (!data) {
+            SDL_OutOfMemory();
+            free(cursor);
+            return NULL;
+        }
         cursor->driverdata = (void *) data;
 
         data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);


More information about the commits mailing list