AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2008.11.24 19:40 "[Tiff] TIFFWriteScanline corrupts buffer when compression with predication is enabled", by William B Thompson
2008.11.26 15:44 "[Tiff] Memory leak opening and closing files?", by Eric Bruneton
2008.11.26 16:54 "Re: [Tiff] Memory leak opening and closing files?", by Frank Warmerdam
2008.11.26 17:13 "Re: [Tiff] Memory leak opening and closing files?", by Bob Friesenhahn
2008.11.27 09:35 "Re: [Tiff] Memory leak opening and closing files?", by Eric Bruneton
2008.11.27 10:22 "Re: [Tiff] Memory leak opening and closing files?", by

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)