[Piglit] [PATCH] texwrap: Fix memory leaks.

Vinson Lee vlee at vmware.com
Sat Dec 3 22:01:26 PST 2011


Fixes Coverity resource leak defect.

Signed-off-by: Vinson Lee <vlee at vmware.com>
---
 tests/texturing/texwrap.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/tests/texturing/texwrap.c b/tests/texturing/texwrap.c
index dae088a..7e82469 100644
--- a/tests/texturing/texwrap.c
+++ b/tests/texturing/texwrap.c
@@ -1211,9 +1211,14 @@ static void init_textures()
         switch (texture_format->internalformat) {
         case GL_DEPTH24_STENCIL8:
             /* Convert to D24X8_UNORM. */
-            {
-                uint32_t *p = (uint32_t*)
-                              (data = malloc(SIZEMAX * SIZEMAX * SIZEMAX * 4));
+           {
+                uint32_t *p;
+
+                if (data != no_border_image) {
+                    free(data);
+                }
+
+                p = (uint32_t*)(data = malloc(SIZEMAX * SIZEMAX * SIZEMAX * 4));
 
                 for (x = 0; x < size_z*size_y*size_x; x++) {
                     p[x] = (uint32_t)(no_border_image[x] * ((1<<24) - 1)) << 8;
@@ -1221,6 +1226,10 @@ static void init_textures()
             }
             break;
         case GL_DEPTH32F_STENCIL8:
+            if (data != no_border_image) {
+                free(data);
+            }
+
             /* Convert to D32F_X24X8. */
             data = malloc(SIZEMAX * SIZEMAX * SIZEMAX * 8);
 
-- 
1.7.7.3



More information about the Piglit mailing list