diff --git a/ChangeLog b/ChangeLog index 87115215..df446f93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-04-28 Even Rouault + + * tools/tiff2bw.c: close TIFF handle in error code path. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2677 + 2017-04-27 Even Rouault * litiff/tif_fax3.c: avoid crash in Fax3Close() on empty file. diff --git a/tools/tiff2bw.c b/tools/tiff2bw.c index 743f455c..90d3973d 100644 --- a/tools/tiff2bw.c +++ b/tools/tiff2bw.c @@ -1,4 +1,4 @@ -/* $Id: tiff2bw.c,v 1.19 2016-08-15 22:01:31 erouault Exp $ */ +/* $Id: tiff2bw.c,v 1.20 2017-04-28 18:08:47 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -165,23 +165,27 @@ main(int argc, char* argv[]) fprintf(stderr, "%s: Bad photometric; can only handle RGB and Palette images.\n", argv[optind]); + TIFFClose(in); return (-1); } TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); if (samplesperpixel != 1 && samplesperpixel != 3) { fprintf(stderr, "%s: Bad samples/pixel %u.\n", argv[optind], samplesperpixel); + TIFFClose(in); return (-1); } if( photometric == PHOTOMETRIC_RGB && samplesperpixel != 3) { fprintf(stderr, "%s: Bad samples/pixel %u for PHOTOMETRIC_RGB.\n", argv[optind], samplesperpixel); + TIFFClose(in); return (-1); } TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample); if (bitspersample != 8) { fprintf(stderr, " %s: Sorry, only handle 8-bit samples.\n", argv[optind]); + TIFFClose(in); return (-1); } TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w); @@ -190,7 +194,10 @@ main(int argc, char* argv[]) out = TIFFOpen(argv[optind+1], "w"); if (out == NULL) + { + TIFFClose(in); return (-1); + } TIFFSetField(out, TIFFTAG_IMAGEWIDTH, w); TIFFSetField(out, TIFFTAG_IMAGELENGTH, h); TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);