From e5ef978e1399416f8e25e312675eaf7d1081c8d4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 3 Oct 2013 20:42:43 -0700 Subject: [PATCH] Fixed a potential double-free bug if glGenTextures() failed. --- src/render/opengl/SDL_render_gl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 824ae8cce..8a61f788f 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -639,8 +639,6 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) } } - texture->driverdata = data; - if (texture->access == SDL_TEXTUREACCESS_TARGET) { data->fbo = GL_GetFBO(renderdata, texture->w, texture->h); } else { @@ -653,6 +651,8 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) SDL_free(data); return -1; } + texture->driverdata = data; + if ((renderdata->GL_ARB_texture_rectangle_supported) /* && texture->access != SDL_TEXTUREACCESS_TARGET */){ data->type = GL_TEXTURE_RECTANGLE_ARB; @@ -804,6 +804,7 @@ GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, data->format, data->formattype, pixels); } renderdata->glDisable(data->type); + return GL_CheckError("glTexSubImage2D()", renderer); } @@ -839,6 +840,7 @@ GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, rect->w/2, rect->h/2, data->format, data->formattype, Vplane); renderdata->glDisable(data->type); + return GL_CheckError("glTexSubImage2D()", renderer); } @@ -1318,7 +1320,9 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h, format, type, temp_pixels); - GL_CheckError("", renderer); + if (GL_CheckError("glReadPixels()", renderer) < 0) { + return -1; + } /* Flip the rows to be top-down */ length = rect->w * SDL_BYTESPERPIXEL(temp_format);