aboutsummaryrefslogtreecommitdiff
path: root/mesalib/progs/util/readtex.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-03-07 16:00:29 +0000
committermarha <marha@users.sourceforge.net>2010-03-07 16:00:29 +0000
commitb40894093babb10f3cd155f11ff2d6c710372395 (patch)
treee6e94e5aa39ca9d5a653af567145e4b5dda25d61 /mesalib/progs/util/readtex.c
parentd27419efcdaaccb40e0f10c549a6b732a2f29e81 (diff)
parent14b1cb8d5a27ec9716d3f790fce95f0469e35605 (diff)
downloadvcxsrv-b40894093babb10f3cd155f11ff2d6c710372395.tar.gz
vcxsrv-b40894093babb10f3cd155f11ff2d6c710372395.tar.bz2
vcxsrv-b40894093babb10f3cd155f11ff2d6c710372395.zip
svn merge ^/branches/released .
Diffstat (limited to 'mesalib/progs/util/readtex.c')
-rw-r--r--mesalib/progs/util/readtex.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/mesalib/progs/util/readtex.c b/mesalib/progs/util/readtex.c
index 8e923b6eb..d1c50a494 100644
--- a/mesalib/progs/util/readtex.c
+++ b/mesalib/progs/util/readtex.c
@@ -109,6 +109,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
raw->file = fopen(baseName + 1, "rb");
if(raw->file == NULL) {
perror(fileName);
+ free(raw);
return NULL;
}
}
@@ -116,7 +117,12 @@ static rawImageRec *RawImageOpen(const char *fileName)
fread(raw, 1, 12, raw->file);
if (swapFlag) {
- ConvertShort(&raw->imagic, 6);
+ ConvertShort(&raw->imagic, 1);
+ ConvertShort(&raw->type, 1);
+ ConvertShort(&raw->dim, 1);
+ ConvertShort(&raw->sizeX, 1);
+ ConvertShort(&raw->sizeY, 1);
+ ConvertShort(&raw->sizeZ, 1);
}
raw->tmp = (unsigned char *)malloc(raw->sizeX*256);
@@ -129,6 +135,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;
}
@@ -138,6 +150,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);
@@ -215,6 +235,7 @@ static void RawImageGetData(rawImageRec *raw, TK_RGBImageRec *final)
final->data = (unsigned char *)malloc((raw->sizeX+1)*(raw->sizeY+1)*4);
if (final->data == NULL) {
fprintf(stderr, "Out of memory!\n");
+ return;
}
ptr = final->data;
@@ -250,6 +271,7 @@ static TK_RGBImageRec *tkRGBImageLoad(const char *fileName)
final = (TK_RGBImageRec *)malloc(sizeof(TK_RGBImageRec));
if (final == NULL) {
fprintf(stderr, "Out of memory!\n");
+ RawImageClose(raw);
return NULL;
}
final->sizeX = raw->sizeX;
@@ -305,6 +327,7 @@ GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target,
fprintf(stderr,
"Error in LoadRGBMipmaps %d-component images not implemented\n",
image->components );
+ FreeImage(image);
return GL_FALSE;
}
@@ -356,6 +379,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;
}
@@ -364,8 +388,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 );
@@ -438,6 +464,7 @@ GLushort *LoadYUVImage( const char *imageFile, GLint *width, GLint *height )
fprintf(stderr,
"Error in LoadYUVImage %d-component images not implemented\n",
image->components );
+ FreeImage(image);
return NULL;
}