You are right - I put the extra FindClose calls just to see if there was not some undocumented behavior causing the memory leaks.
If I change the code to...
WIN32_FIND_DATA w32fd;
HANDLE hFind;
for (int i = 0; i < 1000; i++)
{
hFind = FindFirstFile("*.*",&w32fd
FindNextFile(hFind,&w32fd)
while (FindNextFile(hFind,&w32fd
FindClose(&w32fd);
}
I am still losing 4100KB memory per iteration. If I change the code to...
WIN32_FIND_DATA w32fd;
HANDLE hFind;
for (int i = 0; i < 1000; i++)
{
hFind = FindFirstFile("*.*",&w32fd
FindClose(&w32fd);
}
I still get memory leaks => FindFirstFile and FileNextFile are allocating memory which is not deallocated by FindClose. My thinking is that I have to deallocate the memory referenced by a pointer in w32fd. The question is, what? In more general terms, what do I have to do to get the memory back?
Main Topics
Browse All Topics





by: jasonclarkePosted on 2002-01-16 at 09:14:58ID: 6736882
All those FindClose calls look wrong, I think it should be something like:
);
hFind = FindFirstFile("*.*",&w32fd
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
// Do Something with found file...
} while (FindNextFile(hFind, &w32fd));
FindClose(hFind);
}