From 8481229ff78172c532295ec44b363d7bb9962cb8 Mon Sep 17 00:00:00 2001 From: Mathieu Eyraud <70028899+meyraud705@users.noreply.github.com> Date: Mon, 22 Feb 2021 15:00:52 +0100 Subject: [PATCH] Fix error handling in KMSDRM_AddDisplay Add missing `goto cleanup` and check that `dispdata` is not NULL before dereferencing it. --- src/video/kmsdrm/SDL_kmsdrmvideo.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 9ea06b6a1..602f910a5 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -517,6 +517,7 @@ void KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resource dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); if (!dispdata) { ret = SDL_OutOfMemory(); + goto cleanup; } /* Initialize some of the members of the new display's driverdata @@ -644,15 +645,15 @@ cleanup: KMSDRM_drmModeFreeEncoder(encoder); if (ret) { /* Error (complete) cleanup */ - if (dispdata->connector) { - KMSDRM_drmModeFreeConnector(dispdata->connector); - dispdata->connector = NULL; - } - if (dispdata->crtc) { - KMSDRM_drmModeFreeCrtc(dispdata->crtc); - dispdata->crtc = NULL; - } if (dispdata) { + if (dispdata->connector) { + KMSDRM_drmModeFreeConnector(dispdata->connector); + dispdata->connector = NULL; + } + if (dispdata->crtc) { + KMSDRM_drmModeFreeCrtc(dispdata->crtc); + dispdata->crtc = NULL; + } SDL_free(dispdata); } }