fix resource leaks on error (#2125)
This commit is contained in:
parent
199977b6af
commit
b7b6095407
@ -1,5 +1,9 @@
|
|||||||
2009-11-30 Frank Warmerdam <warmerdam@pobox.com>
|
2009-11-30 Frank Warmerdam <warmerdam@pobox.com>
|
||||||
|
|
||||||
|
* 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
|
* libtiff/tif_{aux.c,dir.c,dir.h,dirinfo.c}: Return to handling
|
||||||
TIFFTAG_REFERENCEBLACKWHITE as a field in the TIFF directory instead
|
TIFFTAG_REFERENCEBLACKWHITE as a field in the TIFF directory instead
|
||||||
of as a custom(generic) field to avoid a potential reentrancy problem.
|
of as a custom(generic) field to avoid a potential reentrancy problem.
|
||||||
|
@ -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
|
* 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) {
|
if ((tif = TIFFOpen(argv[3], "w")) == NULL) {
|
||||||
fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]);
|
fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]);
|
||||||
|
free(gray);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* 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) {
|
if ((tif = TIFFOpen(argv[3], "w")) == NULL) {
|
||||||
fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]);
|
fprintf(stderr, "can't open %s as a TIFF file\n", argv[3]);
|
||||||
|
free(red);free(green);free(blue);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* Copyright (c) 1988-1997 Sam Leffler
|
||||||
@ -94,6 +94,7 @@ main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
if (fread(&h, sizeof (h), 1, in) != 1) {
|
if (fread(&h, sizeof (h), 1, in) != 1) {
|
||||||
fprintf(stderr, "%s: Can not read header.\n", argv[optind]);
|
fprintf(stderr, "%s: Can not read header.\n", argv[optind]);
|
||||||
|
fclose(in);
|
||||||
return (-2);
|
return (-2);
|
||||||
}
|
}
|
||||||
if (strcmp(h.ras_magic, RAS_MAGIC) == 0) {
|
if (strcmp(h.ras_magic, RAS_MAGIC) == 0) {
|
||||||
@ -118,11 +119,15 @@ main(int argc, char* argv[])
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: Not a rasterfile.\n", argv[optind]);
|
fprintf(stderr, "%s: Not a rasterfile.\n", argv[optind]);
|
||||||
|
fclose(in);
|
||||||
return (-3);
|
return (-3);
|
||||||
}
|
}
|
||||||
out = TIFFOpen(argv[optind+1], "w");
|
out = TIFFOpen(argv[optind+1], "w");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
|
{
|
||||||
|
fclose(in);
|
||||||
return (-4);
|
return (-4);
|
||||||
|
}
|
||||||
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) h.ras_width);
|
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) h.ras_width);
|
||||||
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) h.ras_height);
|
TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) h.ras_height);
|
||||||
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||||
@ -224,6 +229,7 @@ main(int argc, char* argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(void) TIFFClose(out);
|
(void) TIFFClose(out);
|
||||||
|
fclose(in);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user