summaryrefslogtreecommitdiffstats
path: root/progs/samples/rgbtoppm.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/samples/rgbtoppm.c')
-rw-r--r--progs/samples/rgbtoppm.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/progs/samples/rgbtoppm.c b/progs/samples/rgbtoppm.c
index 116d9a8cfa5..dcb74228dff 100644
--- a/progs/samples/rgbtoppm.c
+++ b/progs/samples/rgbtoppm.c
@@ -86,13 +86,19 @@ static ImageRec *ImageOpen(char *fileName)
exit(1);
}
if ((image->file = fopen(fileName, "rb")) == NULL) {
- return NULL;
+ free(image);
+ return NULL;
}
fread(image, 1, 12, image->file);
if (swapFlag) {
- ConvertShort(&image->imagic, 6);
+ ConvertShort(&image->imagic, 1);
+ ConvertShort(&image->type, 1);
+ ConvertShort(&image->dim, 1);
+ ConvertShort(&image->xsize, 1);
+ ConvertShort(&image->ysize, 1);
+ ConvertShort(&image->zsize, 1);
}
image->tmp = (unsigned char *)malloc(image->xsize*256);
@@ -224,6 +230,7 @@ read_rgb_texture(char *name, int *width, int *height)
if (gbuf) free(gbuf);
if (bbuf) free(bbuf);
if (abuf) free(abuf);
+ ImageClose(image);
return NULL;
}
ptr = base;