aboutsummaryrefslogtreecommitdiffstats
path: root/src/bmp.c
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-25 16:20:40 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-25 16:20:40 -0700
commit45cf68a160f94d1091c3e5c69237505b138daf25 (patch)
tree33b3c29257f6f983b90174caeaa03f60c856de69 /src/bmp.c
parent665c97078cfa687273e89c8b969d08f5290bcc01 (diff)
downloadmirror-meh-45cf68a160f94d1091c3e5c69237505b138daf25.tar.gz
mirror-meh-45cf68a160f94d1091c3e5c69237505b138daf25.tar.bz2
mirror-meh-45cf68a160f94d1091c3e5c69237505b138daf25.zip
added close method. Fixed all known memory leaks
Diffstat (limited to 'src/bmp.c')
-rw-r--r--src/bmp.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/bmp.c b/src/bmp.c
index e071c15..23780f3 100644
--- a/src/bmp.c
+++ b/src/bmp.c
@@ -10,6 +10,7 @@ struct rgb_t{
struct bmp_t{
struct image img;
+ FILE *f;
unsigned long bitmapoffset;
int compression;
int bpp;
@@ -43,7 +44,7 @@ struct image *bmp_open(FILE *f){
return NULL;
b = malloc(sizeof(struct bmp_t));
- b->img.f = f;
+ b->f = f;
fseek(f, 10, SEEK_SET);
b->bitmapoffset = getlong(f);
@@ -151,7 +152,7 @@ int bmp_read(struct image *img){
unsigned int i, y;
unsigned int dy;
unsigned char *row;
- FILE *f = img->f;
+ FILE *f = b->f;
row = malloc(b->rowwidth);
dy = img->width * 3;
@@ -170,8 +171,15 @@ int bmp_read(struct image *img){
return 0;
}
+void bmp_close(struct image *img){
+ struct bmp_t *b = (struct bmp_t *)img;
+ free(b->colours);
+ fclose(b->f);
+}
+
struct imageformat bmp = {
bmp_open,
- bmp_read
+ bmp_read,
+ bmp_close
};