Fixing valgrind errors.
authorBob Pendleton
Thu, 06 Mar 2008 17:08:10 +0000
changeset 2322c25d45b7add3
parent 2321 c5feceb0395e
child 2323 4ac07ae446d3
Fixing valgrind errors.

One of the error was the result of an unitended recursive call to X11_GL_LoadLibrary which was also fixed.
src/SDL_compat.c
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11window.c
     1.1 --- a/src/SDL_compat.c	Tue Mar 04 23:09:28 2008 +0000
     1.2 +++ b/src/SDL_compat.c	Thu Mar 06 17:08:10 2008 +0000
     1.3 @@ -397,8 +397,8 @@
     1.4      }
     1.5      if (SDL_VideoWindow) {
     1.6          SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
     1.7 +        SDL_DestroyWindow(SDL_VideoWindow);
     1.8      }
     1.9 -    SDL_DestroyWindow(SDL_VideoWindow);
    1.10  
    1.11      /* Set up the event filter */
    1.12      if (!SDL_GetEventFilter(NULL, NULL)) {
     2.1 --- a/src/video/x11/SDL_x11opengl.c	Tue Mar 04 23:09:28 2008 +0000
     2.2 +++ b/src/video/x11/SDL_x11opengl.c	Thu Mar 06 17:08:10 2008 +0000
     2.3 @@ -65,6 +65,8 @@
     2.4  #define GL_UnloadObject	SDL_UnloadObject
     2.5  #endif
     2.6  
     2.7 +static int X11_GL_InitializeMemory(_THIS);
     2.8 +
     2.9  int
    2.10  X11_GL_LoadLibrary(_THIS, const char *path)
    2.11  {
    2.12 @@ -90,7 +92,8 @@
    2.13          return -1;
    2.14      }
    2.15      // LoadLibrary may be called before WindowCreate!
    2.16 -    X11_GL_Initialize(_this);
    2.17 +    // Must create the memory used by GL
    2.18 +    X11_GL_InitializeMemory(_this);
    2.19  
    2.20      /* Load new function pointers */
    2.21      _this->gl_data->glXGetProcAddress =
    2.22 @@ -254,11 +257,10 @@
    2.23      /*     X11_PumpEvents(_this); */ /* can't do that because the windowlist may be inconsitent at this point */
    2.24  }
    2.25  
    2.26 -int
    2.27 -X11_GL_Initialize(_THIS)
    2.28 +static int
    2.29 +X11_GL_InitializeMemory(_THIS)
    2.30  {
    2.31      if (_this->gl_data) {
    2.32 -        ++_this->gl_data->initialized;
    2.33          return 0;
    2.34      }
    2.35  
    2.36 @@ -270,18 +272,30 @@
    2.37          SDL_OutOfMemory();
    2.38          return -1;
    2.39      }
    2.40 -    _this->gl_data->initialized = 1;
    2.41 -
    2.42 -    if (X11_GL_LoadLibrary(_this, NULL) < 0) {
    2.43 -        return -1;
    2.44 -    }
    2.45 -
    2.46 -    /* Initialize extensions */
    2.47 -    X11_GL_InitExtensions(_this);
    2.48 +    _this->gl_data->initialized = 0;
    2.49  
    2.50      return 0;
    2.51  }
    2.52  
    2.53 +int
    2.54 +X11_GL_Initialize(_THIS)
    2.55 +{
    2.56 +
    2.57 +  if (X11_GL_InitializeMemory(_this) < 0) {
    2.58 +     return -1;
    2.59 +  }
    2.60 +  ++_this->gl_data->initialized;
    2.61 +
    2.62 +  if (X11_GL_LoadLibrary(_this, NULL) < 0) {
    2.63 +    return -1;
    2.64 +  }
    2.65 +
    2.66 +  /* Initialize extensions */
    2.67 +  X11_GL_InitExtensions(_this);
    2.68 +
    2.69 +  return 0;
    2.70 +}
    2.71 +
    2.72  void
    2.73  X11_GL_Shutdown(_THIS)
    2.74  {
     3.1 --- a/src/video/x11/SDL_x11window.c	Tue Mar 04 23:09:28 2008 +0000
     3.2 +++ b/src/video/x11/SDL_x11window.c	Thu Mar 06 17:08:10 2008 +0000
     3.3 @@ -56,20 +56,6 @@
     3.4      data->created = created;
     3.5      data->videodata = videodata;
     3.6  
     3.7 -    /* Associate the data with the window */
     3.8 -    windowlist =
     3.9 -        (SDL_WindowData **) SDL_realloc(windowlist,
    3.10 -                                        (numwindows +
    3.11 -                                         1) * sizeof(*windowlist));
    3.12 -    if (!windowlist) {
    3.13 -        SDL_OutOfMemory();
    3.14 -        SDL_free(data);
    3.15 -        return -1;
    3.16 -    }
    3.17 -    windowlist[numwindows++] = data;
    3.18 -    videodata->numwindows = numwindows;
    3.19 -    videodata->windowlist = windowlist;
    3.20 -
    3.21      /* Fill in the SDL window with the window data */
    3.22      {
    3.23          XWindowAttributes attrib;
    3.24 @@ -228,6 +214,7 @@
    3.25                      return -1;
    3.26                  }
    3.27                  SDL_memcpy(&cmap, stdmaps, sizeof(XStandardColormap));
    3.28 +                XFree(stdmaps);
    3.29              }
    3.30  
    3.31              /* OK, we have the best color map, now copy it for use by the
    3.32 @@ -655,6 +642,7 @@
    3.33              XDestroyWindow(display, data->window);
    3.34          }
    3.35          SDL_free(data);
    3.36 +        window->driverdata = NULL;
    3.37      }
    3.38  }
    3.39