radeon: Fix memory leak in radeonCreateScreen2.
[mesa.git] / src / mesa / swrast / s_texture.c
index 8df4b84398ee8e8915017684aaa63ba7b5a029de..8ae3d5bd0e6c8b285a76219a45502011dac7fdf8 100644 (file)
@@ -29,6 +29,7 @@
 #include "main/context.h"
 #include "main/fbobject.h"
 #include "main/teximage.h"
+#include "main/texobj.h"
 #include "swrast/swrast.h"
 #include "swrast/s_context.h"
 
@@ -82,7 +83,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
     * We allocate the array for 1D/2D textures too in order to avoid special-
     * case code in the texstore routines.
     */
-   swImg->ImageOffsets = (GLuint *) malloc(texImage->Depth * sizeof(GLuint));
+   swImg->ImageOffsets = malloc(texImage->Depth * sizeof(GLuint));
    if (!swImg->ImageOffsets)
       return GL_FALSE;
 
@@ -143,10 +144,8 @@ _swrast_free_texture_image_buffer(struct gl_context *ctx,
       swImage->Buffer = NULL;
    }
 
-   if (swImage->ImageOffsets) {
-      free(swImage->ImageOffsets);
-      swImage->ImageOffsets = NULL;
-   }
+   free(swImage->ImageOffsets);
+   swImage->ImageOffsets = NULL;
 }
 
 
@@ -246,7 +245,7 @@ _swrast_unmap_teximage(struct gl_context *ctx,
 void
 _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
-   const GLuint faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint faces = _mesa_num_tex_faces(texObj->Target);
    GLuint face, level;
 
    for (face = 0; face < faces; face++) {
@@ -267,7 +266,7 @@ _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
 void
 _swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
 {
-   const GLuint faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint faces = _mesa_num_tex_faces(texObj->Target);
    GLuint face, level;
 
    for (face = 0; face < faces; face++) {