Fixed crash if initialization of EGL failed but was tried again later.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 21 Jun 2015 17:33:46 +0200
changeset 977130a317c4af6c
parent 9770 2d9b36c5e49d
child 9772 ef27c10db4bf
Fixed crash if initialization of EGL failed but was tried again later.

The internal function SDL_EGL_LoadLibrary() did not delete and remove a mostly
uninitialized data structure if loading the library first failed. A later try to
use EGL then skipped initialization and assumed it was previously successful
because the data structure now already existed. This led to at least one crash
in the internal function SDL_EGL_ChooseConfig() because a NULL pointer was
dereferenced to make a call to eglBindAPI().
src/video/SDL_egl.c
     1.1 --- a/src/video/SDL_egl.c	Sat Jun 20 11:15:37 2015 +0200
     1.2 +++ b/src/video/SDL_egl.c	Sun Jun 21 17:33:46 2015 +0200
     1.3 @@ -72,6 +72,7 @@
     1.4  _this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
     1.5  if (!_this->egl_data->NAME) \
     1.6  { \
     1.7 +    SDL_EGL_UnloadLibrary(_this); \
     1.8      return SDL_SetError("Could not retrieve EGL function " #NAME); \
     1.9  }
    1.10      
    1.11 @@ -219,6 +220,7 @@
    1.12      _this->egl_data->egl_dll_handle = egl_dll_handle;
    1.13  
    1.14      if (egl_dll_handle == NULL) {
    1.15 +        SDL_EGL_UnloadLibrary(_this);
    1.16          return SDL_SetError("Could not initialize OpenGL / GLES library");
    1.17      }
    1.18  
    1.19 @@ -240,6 +242,7 @@
    1.20              if (dll_handle != NULL) {
    1.21                  SDL_UnloadObject(dll_handle);
    1.22              }
    1.23 +            SDL_EGL_UnloadLibrary(_this);
    1.24              return SDL_SetError("Could not load EGL library");
    1.25          }
    1.26          SDL_ClearError();
    1.27 @@ -269,10 +272,12 @@
    1.28  #if !defined(__WINRT__)
    1.29      _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
    1.30      if (!_this->egl_data->egl_display) {
    1.31 +        SDL_EGL_UnloadLibrary(_this);
    1.32          return SDL_SetError("Could not get EGL display");
    1.33      }
    1.34      
    1.35      if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
    1.36 +        SDL_EGL_UnloadLibrary(_this);
    1.37          return SDL_SetError("Could not initialize EGL");
    1.38      }
    1.39  #endif