Fixed a potential double-free bug if glGenTextures() failed.
authorSam Lantinga <slouken@libsdl.org>
Thu, 03 Oct 2013 20:42:43 -0700
changeset 7779 d46f8afbcb17
parent 7778 a571a9947869
child 7780 e45655d26582
Fixed a potential double-free bug if glGenTextures() failed.
src/render/opengl/SDL_render_gl.c
--- a/src/render/opengl/SDL_render_gl.c	Thu Oct 03 10:28:10 2013 -0300
+++ b/src/render/opengl/SDL_render_gl.c	Thu Oct 03 20:42:43 2013 -0700
@@ -639,8 +639,6 @@
         }
     }
 
-    texture->driverdata = data;
-
     if (texture->access == SDL_TEXTUREACCESS_TARGET) {
         data->fbo = GL_GetFBO(renderdata, texture->w, texture->h);
     } else {
@@ -653,6 +651,8 @@
         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 @@
                                     data->format, data->formattype, pixels);
     }
     renderdata->glDisable(data->type);
+
     return GL_CheckError("glTexSubImage2D()", renderer);
 }
 
@@ -839,6 +840,7 @@
                                 rect->w/2, rect->h/2,
                                 data->format, data->formattype, Vplane);
     renderdata->glDisable(data->type);
+
     return GL_CheckError("glTexSubImage2D()", renderer);
 }
 
@@ -1318,7 +1320,9 @@
     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);