2008.11.26 15:44 "[Tiff] Memory leak opening and closing files?", by Eric Bruneton
Hi,
the following program shows a constant increase in memory usage, so I suspect a memory leak in the tiff library (using libtiff 3.8.2-1 on Windows):
for (int i = 0; i < 1000000; ++i) {
TIFF *f = TIFFOpen("test.tiff", "rb");
TIFFClose(f);
}
where "test.tiff" is generated with (in fact I observed this behavior with many different test files):
unsigned char* tile = new unsigned char[32 * 32];
for (int i = 0; i < 32 * 32; ++i) {
tile[i] = (i + i/32)%2 * 255;
}
TIFF* f = TIFFOpen("test.tiff", "wb");
TIFFSetField(f, TIFFTAG_IMAGEWIDTH, 32);
TIFFSetField(f, TIFFTAG_IMAGELENGTH, 32);
TIFFSetField( TIFFTAG_SAMPLESPERPIXEL, 1); f,
TIFFSetField( TIFFTAG_BITSPERSAMPLE, 8); f,
TIFFSetField(f, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(f, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
TIFFSetField( TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); f,
TIFFSetField( TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); f,
TIFFWriteEncodedStrip(f, 0, tile, 32 * 32);
TIFFClose(f);
note that this program:
for (int i = 0; i < 1000000; ++i) {
FILE *f = fopen("test.tiff", "rb");
fclose(f);
}
does not show this behavior.
Eric
PS I tried calling _TIFFfree((void*) TIFFFileName(f)); before TIFFClose (it seems this is not done in TIFFClose). It does not crash, but it does not solve the problem (memory usage still increasing with time)