diff --git a/ChangeLog b/ChangeLog index e63cc247..7364bcfd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-11-30 Frank Warmerdam + * contrib/dbs/tiff-grayscale.c, contrib/tif-palette.c, + tools/ras2tiff.c: Fix resource leaks on error. + http://bugzilla.maptools.org/show_bug.cgi?id=2121 + * libtiff/tif_{aux.c,dir.c,dir.h,dirinfo.c}: Return to handling TIFFTAG_REFERENCEBLACKWHITE as a field in the TIFF directory instead of as a custom(generic) field to avoid a potential reentrancy problem. diff --git a/contrib/dbs/tiff-grayscale.c b/contrib/dbs/tiff-grayscale.c index c0b50f2e..9dcadc03 100644 --- a/contrib/dbs/tiff-grayscale.c +++ b/contrib/dbs/tiff-grayscale.c @@ -1,4 +1,4 @@ -/* $Id: tiff-grayscale.c,v 1.4 2004-09-03 08:26:08 dron Exp $ */ +/* $Id: tiff-grayscale.c,v 1.5 2009-11-30 18:42:53 fwarmerdam Exp $ */ /* * tiff-grayscale.c -- create a Class G (grayscale) TIFF file @@ -86,6 +86,7 @@ int main(int argc, char **argv) if ((tif = TIFFOpen(argv[3], "w")) == NULL) { fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]); + free(gray); return 0; } diff --git a/contrib/dbs/tiff-palette.c b/contrib/dbs/tiff-palette.c index a8e13509..a8bbeb80 100644 --- a/contrib/dbs/tiff-palette.c +++ b/contrib/dbs/tiff-palette.c @@ -1,4 +1,4 @@ -/* $Id: tiff-palette.c,v 1.3 2004-09-03 08:27:20 dron Exp $ */ +/* $Id: tiff-palette.c,v 1.4 2009-11-30 18:42:53 fwarmerdam Exp $ */ /* * tiff-palette.c -- create a Class P (palette) TIFF file @@ -219,6 +219,7 @@ int main(int argc, char **argv) if ((tif = TIFFOpen(argv[3], "w")) == NULL) { fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]); + free(red);free(green);free(blue); return 0; } diff --git a/tools/ras2tiff.c b/tools/ras2tiff.c index 757b30fa..ec456f2f 100644 --- a/tools/ras2tiff.c +++ b/tools/ras2tiff.c @@ -1,4 +1,4 @@ -/* $Id: ras2tiff.c,v 1.16 2009-01-22 20:53:07 fwarmerdam Exp $ */ +/* $Id: ras2tiff.c,v 1.17 2009-11-30 18:42:53 fwarmerdam Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -94,6 +94,7 @@ main(int argc, char* argv[]) } if (fread(&h, sizeof (h), 1, in) != 1) { fprintf(stderr, "%s: Can not read header.\n", argv[optind]); + fclose(in); return (-2); } if (strcmp(h.ras_magic, RAS_MAGIC) == 0) { @@ -118,11 +119,15 @@ main(int argc, char* argv[]) #endif } else { fprintf(stderr, "%s: Not a rasterfile.\n", argv[optind]); + fclose(in); return (-3); } out = TIFFOpen(argv[optind+1], "w"); if (out == NULL) + { + fclose(in); return (-4); + } TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) h.ras_width); TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) h.ras_height); TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); @@ -224,6 +229,7 @@ main(int argc, char* argv[]) break; } (void) TIFFClose(out); + fclose(in); return (0); }