Mesa (mesa_7_6_branch): progs/util: Fix memory leak if LoadRGBImage fails.

Vinson Lee vlee at kemper.freedesktop.org
Fri Dec 4 00:24:24 UTC 2009


Module: Mesa
Branch: mesa_7_6_branch
Commit: f1172c4030dd0952dfdecda059beb39b1224a8ae
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f1172c4030dd0952dfdecda059beb39b1224a8ae

Author: Vinson Lee <vlee at vmware.com>
Date:   Tue Nov 17 10:11:50 2009 -0800

progs/util: Fix memory leak if LoadRGBImage fails.
(cherry picked from commit 041cd0e110d41b543a0fe9cc484ae8373642912b)

---

 progs/util/readtex.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/progs/util/readtex.c b/progs/util/readtex.c
index 4e22bed..ec27e20 100644
--- a/progs/util/readtex.c
+++ b/progs/util/readtex.c
@@ -357,6 +357,7 @@ GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height,
       fprintf(stderr,
               "Error in LoadRGBImage %d-component images not implemented\n",
               image->components );
+      FreeImage(image);
       return NULL;
    }
 
@@ -365,8 +366,10 @@ GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height,
 
    bytes = image->sizeX * image->sizeY * image->components;
    buffer = (GLubyte *) malloc(bytes);
-   if (!buffer)
+   if (!buffer) {
+      FreeImage(image);
       return NULL;
+   }
 
    memcpy( (void *) buffer, (void *) image->data, bytes );
 




More information about the mesa-commit mailing list