progs/util: Fix memory leak if malloc fails in RawImageOpen.
authorVinson Lee <vlee@vmware.com>
Fri, 20 Nov 2009 19:22:13 +0000 (11:22 -0800)
committerVinson Lee <vlee@vmware.com>
Fri, 20 Nov 2009 19:22:13 +0000 (11:22 -0800)
progs/util/readtex.c

index 3922998fd5bc4040ede90734c687e3e7cbc2e985..1e1183cf9ac8bfcd21ede53b23c2a3198b8a117c 100644 (file)
@@ -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);