kmsdrm: Add missing checks after SDL_calloc() calls.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 6211de7..6b447e1 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -545,6 +545,9 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
*plane = SDL_calloc(1, sizeof(**plane));
+ if (!(*plane)) {
+ return SDL_OutOfMemory();
+ }
/* Get plane ID. */
plane_id = get_plane_id(_this, plane_type);
@@ -561,10 +564,14 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
unsigned int i;
(*plane)->props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd,
(*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE);
-
(*plane)->props_info = SDL_calloc((*plane)->props->count_props,
sizeof(*(*plane)->props_info));
+ if ( !((*plane)->props_info) ) {
+ SDL_OutOfMemory();
+ goto cleanup;
+ }
+
for (i = 0; i < (*plane)->props->count_props; i++) {
(*plane)->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
(*plane)->props->props[i]);
@@ -876,7 +883,6 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
/* Create a structure that contains the info about framebuffer
that we need to use it. */
fb_info = (KMSDRM_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo));
-
if (!fb_info) {
SDL_OutOfMemory();
return NULL;
@@ -1139,9 +1145,16 @@ KMSDRM_VideoInit(_THIS)
SDL_VideoDisplay display = {0};
dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
+ if (!dispdata) {
+ return SDL_OutOfMemory();
+ }
+
dispdata->display_plane = SDL_calloc(1, sizeof(*dispdata->display_plane));
dispdata->crtc = SDL_calloc(1, sizeof(*dispdata->crtc));
dispdata->connector = SDL_calloc(1, sizeof(*dispdata->connector));
+ if (!(dispdata->display_plane) || !(dispdata->crtc) || !(dispdata->connector)) {
+ return SDL_OutOfMemory();
+ }
dispdata->atomic_flags = 0;
dispdata->atomic_req = NULL;
@@ -1151,10 +1164,6 @@ KMSDRM_VideoInit(_THIS)
dispdata->dumb_buffer = NULL;
dispdata->modeset_pending = SDL_FALSE;
- if (!dispdata) {
- return SDL_OutOfMemory();
- }
-
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()");
/* Open /dev/dri/cardNN */
@@ -1337,6 +1346,11 @@ KMSDRM_VideoInit(_THIS)
dispdata->crtc->props_info = SDL_calloc(dispdata->crtc->props->count_props,
sizeof(*dispdata->crtc->props_info));
+
+ if (!dispdata->crtc->props_info) {
+ ret = SDL_OutOfMemory();
+ goto cleanup;
+ }
for (i = 0; i < dispdata->crtc->props->count_props; i++) {
dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
@@ -1350,6 +1364,11 @@ KMSDRM_VideoInit(_THIS)
dispdata->connector->props_info = SDL_calloc(dispdata->connector->props->count_props,
sizeof(*dispdata->connector->props_info));
+ if (!dispdata->connector->props_info) {
+ ret = SDL_OutOfMemory();
+ goto cleanup;
+ }
+
for (i = 0; i < dispdata->connector->props->count_props; i++) {
dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
dispdata->connector->props->props[i]);
@@ -1579,9 +1598,12 @@ KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
for (i = 0; i < conn->count_modes; i++) {
SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData));
- if (modedata) {
- modedata->mode_index = i;
+ if (!modedata) {
+ SDL_OutOfMemory();
+ return;
}
+
+ modedata->mode_index = i;
mode.w = conn->modes[i].hdisplay;
mode.h = conn->modes[i].vdisplay;
@@ -1651,13 +1673,17 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window)
/* Allocate window internal data */
windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
+ if (!windata) {
+ SDL_OutOfMemory();
+ goto error;
+ }
display = SDL_GetDisplayForWindow(window);
dispdata = display->driverdata;
if (((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) ||
- ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)) {
-
+ ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN))
+ {
windata->src_w = dispdata->mode.hdisplay;
windata->src_h = dispdata->mode.vdisplay;
windata->output_w = dispdata->mode.hdisplay;