kmsdrm: Fixed crashes if allocating memory failed.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 05 Aug 2017 22:10:36 +0200
changeset 11190478630f6b756
parent 11189 8a23ac7134d2
child 11191 c3b94a174d81
kmsdrm: Fixed crashes if allocating memory failed.
src/video/kmsdrm/SDL_kmsdrmopengles.c
src/video/kmsdrm/SDL_kmsdrmvideo.c
     1.1 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c	Sat Aug 05 22:10:25 2017 +0200
     1.2 +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c	Sat Aug 05 22:10:36 2017 +0200
     1.3 @@ -102,6 +102,9 @@
     1.4      }
     1.5  
     1.6      fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
     1.7 +    if (fb_info == NULL) {
     1.8 +        return 0;
     1.9 +    }
    1.10      if (_this->egl_data->egl_swapinterval == 0) {
    1.11          /* Swap buffers instantly, possible tearing */
    1.12          /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModeSetCrtc(%d, %u, %u, 0, 0, &%u, 1, &%ux%u@%u)",
     2.1 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c	Sat Aug 05 22:10:25 2017 +0200
     2.2 +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c	Sat Aug 05 22:10:36 2017 +0200
     2.3 @@ -199,6 +199,10 @@
     2.4  
     2.5      /* Here a new DRM FB must be created */
     2.6      fb_info = (KMSDRM_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo));
     2.7 +    if (fb_info == NULL) {
     2.8 +        SDL_OutOfMemory();
     2.9 +        return NULL;
    2.10 +    }
    2.11      fb_info->drm_fd = vdata->drm_fd;
    2.12  
    2.13      w  = KMSDRM_gbm_bo_get_width(bo);
    2.14 @@ -280,6 +284,10 @@
    2.15  
    2.16      /* Open /dev/dri/cardNN */
    2.17      devname = (char *) SDL_calloc(1, 16);
    2.18 +    if (devname == NULL) {
    2.19 +        ret = SDL_OutOfMemory();
    2.20 +        goto cleanup;
    2.21 +    }
    2.22      SDL_snprintf(devname, 16, "/dev/dri/card%d", vdata->devindex);
    2.23      vdata->drm_fd = open(devname, O_RDWR | O_CLOEXEC);
    2.24      SDL_free(devname);