Mesa (mesa_7_6_branch): progs/util: Fix memory leak if malloc fails in RawImageOpen.

Vinson Lee vlee at kemper.freedesktop.org
Thu Dec 3 17:09:20 PST 2009


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

Author: Vinson Lee <vlee at vmware.com>
Date:   Fri Nov 20 11:22:13 2009 -0800

progs/util: Fix memory leak if malloc fails in RawImageOpen.
(cherry picked from commit d36cb2396c942f05ba56c5b899792a507bb0f0fd)

---

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

diff --git a/progs/util/readtex.c b/progs/util/readtex.c
index 3922998..1e1183c 100644
--- a/progs/util/readtex.c
+++ b/progs/util/readtex.c
@@ -130,6 +130,12 @@ static rawImageRec *RawImageOpen(const char *fileName)
    if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL ||
        raw->tmpB == NULL) {
       fprintf(stderr, "Out of memory!\n");
+      free(raw->tmp);
+      free(raw->tmpR);
+      free(raw->tmpG);
+      free(raw->tmpB);
+      free(raw->tmpA);
+      free(raw);
       return NULL;
    }
 
@@ -139,6 +145,14 @@ static rawImageRec *RawImageOpen(const char *fileName)
       raw->rowSize = (GLint *)malloc(x);
       if (raw->rowStart == NULL || raw->rowSize == NULL) {
          fprintf(stderr, "Out of memory!\n");
+         free(raw->tmp);
+         free(raw->tmpR);
+         free(raw->tmpG);
+         free(raw->tmpB);
+         free(raw->tmpA);
+         free(raw->rowStart);
+         free(raw->rowSize);
+         free(raw);
          return NULL;
       }
       raw->rleEnd = 512 + (2 * x);



More information about the mesa-commit mailing list