Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
SDL_GL_DeleteContext would leave an invalid current_glctx.
Browse files Browse the repository at this point in the history
Calling SDL_GL_DeleteContext wouldn't update current_glctx, so you could
end up with use-after-free and other goodies when you deleted a context.
  • Loading branch information
jorgenpt committed Apr 23, 2013
1 parent 5d65ee4 commit e28fa1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/render/opengl/SDL_render_gl.c
Expand Up @@ -1241,8 +1241,7 @@ GL_DestroyRenderer(SDL_Renderer * renderer)
GL_CheckError("", renderer);
SDL_free(data->framebuffers);
data->framebuffers = nextnode;
}
/* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
}
SDL_GL_DeleteContext(data->context);
}
SDL_free(data);
Expand Down
17 changes: 11 additions & 6 deletions src/video/SDL_video.c
Expand Up @@ -2690,13 +2690,14 @@ SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
{
int retval;

CHECK_WINDOW_MAGIC(window, -1);

if (!(window->flags & SDL_WINDOW_OPENGL)) {
return SDL_SetError("The specified window isn't an OpenGL window");
}
if (!ctx) {
window = NULL;
} else {
CHECK_WINDOW_MAGIC(window, -1);

if (!(window->flags & SDL_WINDOW_OPENGL)) {
return SDL_SetError("The specified window isn't an OpenGL window");
}
}

if ((window == _this->current_glwin) && (ctx == _this->current_glctx)) {
Expand Down Expand Up @@ -2758,7 +2759,11 @@ SDL_GL_DeleteContext(SDL_GLContext context)
if (!_this || !context) {
return;
}
_this->GL_MakeCurrent(_this, NULL, NULL);

if (_this->current_glctx == context) {
SDL_GL_MakeCurrent(NULL, NULL);
}

_this->GL_DeleteContext(_this, context);
}

Expand Down

0 comments on commit e28fa1b

Please sign in to comment.