Fixed bug 4296 - kmsdrm video driver leaks 1 bo in KMSDRM_GLES_SetupCrtc()
authorSam Lantinga <slouken@libsdl.org>
Fri, 05 Oct 2018 17:06:05 -0700
changeset 12299d8683d6ff2f8
parent 12298 c4d5e502c1f4
child 12304 27ba030d839f
Fixed bug 4296 - kmsdrm video driver leaks 1 bo in KMSDRM_GLES_SetupCrtc()

Icenowy Zheng

One front buffer is locked in GLES_SetupCrtc() and overrides the next_bo just locked in KMSDRM_GLES_SwapWindow, then the next_bo gets lost and is not released even when quitting the video.

It may leads to problems with GLES drivers that doesn't clean up GBM correctly if there's any bo left (e.g. the Mali Utgard r6p2 blob). In the case of Mali Utgard r6p2 blob, the DRM device file is still hold by the blob, and if you try to SDL_Quit to let another program to run (this is done by EmulationStation), the new program will fail to open DRM device.
src/video/kmsdrm/SDL_kmsdrmopengles.c
src/video/kmsdrm/SDL_kmsdrmvideo.c
src/video/kmsdrm/SDL_kmsdrmvideo.h
     1.1 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c	Fri Oct 05 17:24:03 2018 -0400
     1.2 +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c	Fri Oct 05 17:06:05 2018 -0700
     1.3 @@ -54,13 +54,13 @@
     1.4          return SDL_FALSE;
     1.5      }
     1.6  
     1.7 -    wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
     1.8 -    if (wdata->next_bo == NULL) {
     1.9 +    wdata->crtc_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
    1.10 +    if (wdata->crtc_bo == NULL) {
    1.11          SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup");
    1.12          return SDL_FALSE;
    1.13      }
    1.14  
    1.15 -    fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
    1.16 +    fb_info = KMSDRM_FBFromBO(_this, wdata->crtc_bo);
    1.17      if (fb_info == NULL) {
    1.18          return SDL_FALSE;
    1.19      }
     2.1 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c	Fri Oct 05 17:24:03 2018 -0400
     2.2 +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c	Fri Oct 05 17:06:05 2018 -0700
     2.3 @@ -566,6 +566,10 @@
     2.4      if(data) {
     2.5          /* Wait for any pending page flips and unlock buffer */
     2.6          KMSDRM_WaitPageFlip(_this, data, -1);
     2.7 +        if (data->crtc_bo != NULL) {
     2.8 +            KMSDRM_gbm_surface_release_buffer(data->gs, data->crtc_bo);
     2.9 +            data->crtc_bo = NULL;
    2.10 +        }
    2.11          if (data->next_bo != NULL) {
    2.12              KMSDRM_gbm_surface_release_buffer(data->gs, data->next_bo);
    2.13              data->next_bo = NULL;
     3.1 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h	Fri Oct 05 17:24:03 2018 -0400
     3.2 +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h	Fri Oct 05 17:06:05 2018 -0700
     3.3 @@ -62,6 +62,7 @@
     3.4      struct gbm_surface *gs;
     3.5      struct gbm_bo *current_bo;
     3.6      struct gbm_bo *next_bo;
     3.7 +    struct gbm_bo *crtc_bo;
     3.8      SDL_bool waiting_for_flip;
     3.9      SDL_bool crtc_ready;
    3.10      SDL_bool double_buffer;