2004.10.21 14:52 "[Tiff] Memory Leak?", by Harith Frangoul

2004.10.21 14:52 "[Tiff] Memory Leak?", by Harith Frangoul

Hi.

I'm using tifflib version 3.1.6.

There is an apparent memory leak in the library.

I wrote a simple program to open and close a tiff file in a loop and watched the memory increase gradually.

Here is the program written as a console app in VS C++ 6.0.

// TiffTest.cpp : Defines the entry point for the console application. 
// 

#include "stdafx.h" 
#include "TiffTest.h" 
#include "tiffio.h" 
#include "direct.h" 

#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 

//////////////////////////////////////////////////////////////////////////// / 
// The one and only application object 

CWinApp theApp; 

using namespace std; 

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) 



            // initialize MFC and print and error on failure 
            if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) 
            { 
                        // TODO: change error code to suit your needs 
                        cerr << _T("Fatal Error: MFC initialization failed") << endl; 
                        return 1; 
            } 

            char exeFilePath[MAX_PATH]; 
            char drive[_MAX_DRIVE]; 
            char dir[_MAX_DIR]; 
            char fname[_MAX_FNAME]; 
            char ext[_MAX_EXT]; 
            CString strFilePath; 
            // get the exe file name 
            GetModuleFileName(0, exeFilePath, MAX_PATH); 
            _splitpath(exeFilePath, drive, dir, fname, ext); 
            strFilePath.Format("%s%s%s", drive, dir, "FILES"); 
            _mkdir((LPCTSTR)strFilePath); 

            strFilePath += "\\CHECK.TIF"; 

            TIFF *image; 

            for (int i = 1; i < 100000; i++) { 

                        //Open the TIFF Image 
                        if((image = TIFFOpen(strFilePath, "rM")) == NULL) { 
                                    printf("Error in opening TIFF\n"); 
                                    break; 
                        } 
                        TIFFClose(image); 
                        image = NULL; 

            } 



            return 0; 
}