diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-25 16:20:40 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-25 16:20:40 -0700 |
commit | 45cf68a160f94d1091c3e5c69237505b138daf25 (patch) | |
tree | 33b3c29257f6f983b90174caeaa03f60c856de69 /src/main.c | |
parent | 665c97078cfa687273e89c8b969d08f5290bcc01 (diff) | |
download | mirror-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/main.c')
-rw-r--r-- | src/main.c | 26 |
1 files changed, 7 insertions, 19 deletions
@@ -69,7 +69,6 @@ void run(){ struct image *img = NULL; XImage *ximg = NULL; int redraw = 0; - FILE *f = NULL; for(;;){ XEvent event; @@ -78,8 +77,6 @@ void run(){ break; XNextEvent(display, &event); switch(event.type){ - case MapNotify: - break; case ConfigureNotify: if(width != event.xconfigure.width || height != event.xconfigure.height){ width = event.xconfigure.width; @@ -138,18 +135,14 @@ void run(){ if(!img){ const char *firstimg = filename; while(!img){ - if(f){ - fclose(f); - f = NULL; - } - if(!(f = fopen(filename, "rb"))) - fprintf(stderr, "Cannot open '%s'\n", filename); - - if(f){ + FILE *f; + if((f = fopen(filename, "rb"))){ if((img = imgopen(f))) break; else fprintf(stderr, "Invalid format '%s'\n", filename); + }else{ + fprintf(stderr, "Cannot open '%s'\n", filename); } filename = direction(); @@ -158,19 +151,14 @@ void run(){ exit(EXIT_FAILURE); } } - img->buf = NULL; + setaspect(img->width, img->height); - continue; /* make sure setaspect can do its thing */ - } - if(!img->buf){ + img->buf = malloc(3 * img->width * img->height); if(img->fmt->read(img)){ fprintf(stderr, "read error!\n"); } - if(f){ - fclose(f); - f = NULL; - } + img->fmt->close(img); continue; /* Allow for some events to be read, read is slow */ } ximg = getimage(img, width, height); |