From ba17f4df4d315a986fc2a3f49c9933377390ef6f Mon Sep 17 00:00:00 2001 From: Bob Pendleton Date: Thu, 6 Mar 2008 17:08:10 +0000 Subject: [PATCH] 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 | 2 +- src/video/x11/SDL_x11opengl.c | 36 ++++++++++++++++++++++++----------- src/video/x11/SDL_x11window.c | 16 ++-------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/SDL_compat.c b/src/SDL_compat.c index fe24748d3..6f1282ac4 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -397,8 +397,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) } if (SDL_VideoWindow) { SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y); + SDL_DestroyWindow(SDL_VideoWindow); } - SDL_DestroyWindow(SDL_VideoWindow); /* Set up the event filter */ if (!SDL_GetEventFilter(NULL, NULL)) { diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index e70f44567..919e6566a 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -65,6 +65,8 @@ #define GL_UnloadObject SDL_UnloadObject #endif +static int X11_GL_InitializeMemory(_THIS); + int X11_GL_LoadLibrary(_THIS, const char *path) { @@ -90,7 +92,8 @@ X11_GL_LoadLibrary(_THIS, const char *path) return -1; } // LoadLibrary may be called before WindowCreate! - X11_GL_Initialize(_this); + // Must create the memory used by GL + X11_GL_InitializeMemory(_this); /* Load new function pointers */ _this->gl_data->glXGetProcAddress = @@ -254,11 +257,10 @@ X11_GL_InitExtensions(_THIS) /* X11_PumpEvents(_this); */ /* can't do that because the windowlist may be inconsitent at this point */ } -int -X11_GL_Initialize(_THIS) +static int +X11_GL_InitializeMemory(_THIS) { if (_this->gl_data) { - ++_this->gl_data->initialized; return 0; } @@ -270,16 +272,28 @@ X11_GL_Initialize(_THIS) SDL_OutOfMemory(); return -1; } - _this->gl_data->initialized = 1; + _this->gl_data->initialized = 0; - if (X11_GL_LoadLibrary(_this, NULL) < 0) { - return -1; - } + return 0; +} - /* Initialize extensions */ - X11_GL_InitExtensions(_this); +int +X11_GL_Initialize(_THIS) +{ - return 0; + if (X11_GL_InitializeMemory(_this) < 0) { + return -1; + } + ++_this->gl_data->initialized; + + if (X11_GL_LoadLibrary(_this, NULL) < 0) { + return -1; + } + + /* Initialize extensions */ + X11_GL_InitExtensions(_this); + + return 0; } void diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index b2bc577ab..b5e28944b 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -56,20 +56,6 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created) data->created = created; data->videodata = videodata; - /* Associate the data with the window */ - windowlist = - (SDL_WindowData **) SDL_realloc(windowlist, - (numwindows + - 1) * sizeof(*windowlist)); - if (!windowlist) { - SDL_OutOfMemory(); - SDL_free(data); - return -1; - } - windowlist[numwindows++] = data; - videodata->numwindows = numwindows; - videodata->windowlist = windowlist; - /* Fill in the SDL window with the window data */ { XWindowAttributes attrib; @@ -228,6 +214,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) return -1; } SDL_memcpy(&cmap, stdmaps, sizeof(XStandardColormap)); + XFree(stdmaps); } /* OK, we have the best color map, now copy it for use by the @@ -655,6 +642,7 @@ X11_DestroyWindow(_THIS, SDL_Window * window) XDestroyWindow(display, data->window); } SDL_free(data); + window->driverdata = NULL; } }