From: Vinson Lee Date: Fri, 20 Nov 2009 19:22:13 +0000 (-0800) Subject: progs/util: Fix memory leak if malloc fails in RawImageOpen. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d36cb2396c942f05ba56c5b899792a507bb0f0fd;p=mesa.git progs/util: Fix memory leak if malloc fails in RawImageOpen. --- diff --git a/progs/util/readtex.c b/progs/util/readtex.c index 3922998fd5b..1e1183cf9ac 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);