Fix error handling in KMSDRM_AddDisplay

Add missing `goto cleanup` and check that `dispdata` is not NULL before dereferencing it.
This commit is contained in:
Mathieu Eyraud 2021-02-22 15:00:52 +01:00 committed by Sam Lantinga
parent 2df9c15e96
commit 8481229ff7

View File

@ -517,6 +517,7 @@ void KMSDRM_AddDisplay (_THIS, drmModeConnector *connector, drmModeRes *resource
dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (!dispdata) { if (!dispdata) {
ret = SDL_OutOfMemory(); ret = SDL_OutOfMemory();
goto cleanup;
} }
/* Initialize some of the members of the new display's driverdata /* Initialize some of the members of the new display's driverdata
@ -644,6 +645,7 @@ cleanup:
KMSDRM_drmModeFreeEncoder(encoder); KMSDRM_drmModeFreeEncoder(encoder);
if (ret) { if (ret) {
/* Error (complete) cleanup */ /* Error (complete) cleanup */
if (dispdata) {
if (dispdata->connector) { if (dispdata->connector) {
KMSDRM_drmModeFreeConnector(dispdata->connector); KMSDRM_drmModeFreeConnector(dispdata->connector);
dispdata->connector = NULL; dispdata->connector = NULL;
@ -652,7 +654,6 @@ cleanup:
KMSDRM_drmModeFreeCrtc(dispdata->crtc); KMSDRM_drmModeFreeCrtc(dispdata->crtc);
dispdata->crtc = NULL; dispdata->crtc = NULL;
} }
if (dispdata) {
SDL_free(dispdata); SDL_free(dispdata);
} }
} }