]> git.webhop.me Git - tuxwetter.git/commitdiff
-fix memory/resource leak
authorsatbaby <satbaby>
Wed, 15 Aug 2012 11:46:14 +0000 (13:46 +0200)
committersatbaby <satbaby>
Wed, 15 Aug 2012 11:53:19 +0000 (13:53 +0200)
bmps.c
build.sh
pngw.c
tuxwetter.c

diff --git a/bmps.c b/bmps.c
index 290d4a153882dfaded33361633635aa804d21cdd..d8f4db4f8f519fc244fb4e11d2be07274da3e67b 100644 (file)
--- a/bmps.c
+++ b/bmps.c
@@ -42,7 +42,6 @@ lcd_packed_buffer s;
 
 int bmp2lcd (char *bildfile) 
 {
-       char bild2lcd [50];
        char filename[50];
        char bmpfile[50];
        
@@ -83,10 +82,12 @@ int bmp2lcd (char *bildfile)
        }
        if (fread(&bh, 1, sizeof(bh), fbmp)!=sizeof(bh)) {
                perror("fread(BMP_HEADER)");
+               fclose(fbmp);
                return(3);
        }
        if ((bh._B!='B')||(bh._M!='M')) {
                fprintf(stderr, "Bad Magic (not a BMP file).\n");
+               fclose(fbmp);
                return(4);
        }
 
@@ -101,9 +102,13 @@ int bmp2lcd (char *bildfile)
        colors = malloc(4<<bh.bit_count);
        if (fread(colors, 1, 4<<bh.bit_count, fbmp)!=4<<bh.bit_count) {
                perror("fread(BMP_COLORS)");
+               fclose(fbmp);
+               if(colors)
+                       free(colors);
                return(5);
        }
-
+       if(colors)
+               free(colors);
        // image
        line_size = (bh.width*bh.bit_count / 8);
        bmpline_size = (line_size + 3) & ~3;
@@ -112,6 +117,9 @@ int bmp2lcd (char *bildfile)
        image = malloc(image_size);
        if (fread(image, 1, image_size, fbmp)!=image_size) {
                perror("fread(BMP_IMAGE)");
+               fclose(fbmp);
+               if(image)
+                       free(image);
                return(6);
        }
        fclose(fbmp);
@@ -122,6 +130,8 @@ int bmp2lcd (char *bildfile)
                printf("WARNING: Image is compressed - result unpredictable.\n");
 
        bmp2raw(bh, image, raw);
+       if(image)
+               free(image);
        raw2packed(raw, s);
 
        if(lcd_fd < 0)
index df7b811f6cfcab8010dbbf7f694d00aa18c1f6f6..5e467acb00e238825ffbba7d7b27d3d530144bbc 100644 (file)
--- a/build.sh
+++ b/build.sh
@@ -1 +1 @@
-arm-cx2450x-linux-gnueabi-gcc -g -o tuxwetter tuxwetter.c gfx.c io.c text.c parser.c php.c http.c jpeg.c fb_display.c resize.c pngw.c gif.c -L$PREFIX/lib -I$PREFIX/include -I$PREFIX/include/freetype2 -O2 -lfreetype -lz -ljpeg  -lpng -lgif -DWWEATHER gifdecomp.c
+arm-cx2450x-linux-gnueabi-gcc -g -o tuxwetter tuxwetter.c gfx.c io.c text.c parser.c php.c http.c jpeg.c fb_display.c resize.c pngw.c gif.c -L$PREFIX/lib -I$PREFIX/include -I$PREFIX/include/freetype2 -O2 -lfreetype -lcurl -lz -ljpeg  -lpng -lungif -DWWEATHER gifdecomp.c
diff --git a/pngw.c b/pngw.c
index cd65f64d37e8fa92e71f12c337dcfbad31b2e53d..127dd93945e244b0c01deeff62c001943fbfec2c 100644 (file)
--- a/pngw.c
+++ b/pngw.c
@@ -62,7 +62,10 @@ int fh_png_load(const char *name,unsigned char *buffer,int x,int y)
        if(!(fh=fopen(name,"rb")))      return(FH_ERROR_FILE);
 
        png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
-       if(png_ptr == NULL) return(FH_ERROR_FORMAT);
+       if(png_ptr == NULL) {
+               fclose(fh);
+               return(FH_ERROR_FORMAT);
+       }
        info_ptr = png_create_info_struct(png_ptr);
        if(info_ptr == NULL)
        {
@@ -146,7 +149,10 @@ int fh_png_getsize(const char *name,int *x,int *y, int wanted_width, int wanted_
        if(!(fh=fopen(name,"rb")))      return(FH_ERROR_FILE);
 
        png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
-       if(png_ptr == NULL) return(FH_ERROR_FORMAT);
+       if(png_ptr == NULL) {
+               fclose(fh);
+               return(FH_ERROR_FORMAT);
+       }
        info_ptr = png_create_info_struct(png_ptr);
        if(info_ptr == NULL)
        {
index 7f21e75bc663cd100d6967cb18987613a2b50ab9..ab79efe4e64ff7d7eeff0b78fc9044cd242f85fa 100644 (file)
@@ -350,7 +350,8 @@ int ReadConf(char *iscmd)
 */
                }
        }
-
+       if(fd_conf)
+               fclose(fd_conf);
        return 1;
 }
 
@@ -2368,18 +2369,21 @@ unsigned char *tbuf=lfb;
                if(fh_png_getsize(ICON_FILE, &x1, &y1, xsize, ysize))
                {
                        printf("Tuxwetter <invalid PNG-Format>\n");
+                       fclose(tfh);
                        return -1;
                }
 #else
                if(fh_gif_getsize(ICON_FILE, &x1, &y1, xsize, ysize))
                {
                        printf("Tuxwetter <invalid GIF-Format>\n");
+                       fclose(tfh);
                        return -1;
                }
 #endif
                if((buffer=(unsigned char *) malloc(x1*y1*4))==NULL)
                {
                        printf(NOMEM);
+                       fclose(tfh);
                        return -1;
                }
 #ifdef WWEATHER
@@ -2424,6 +2428,7 @@ unsigned char *tbuf=lfb;
 
                }
                free(buffer);
+               fclose(tfh);
                lfb=tbuf;
        }
        return (rv)?-1:0;