From Chris Denham, "I discovered a memory leak in the ZIP plugin, which was caused by a missing call to CloseZip.

I attach a modified ReaderWriterZIP.cpp  (based on version 2.9.5 revision 10374).
This includes a little bit of code tidying, but the only functional change is a test of the return value of OpenZip and the addition of a call to CloseZip."
This commit is contained in:
Robert Osfield 2009-10-10 10:00:13 +00:00
parent ae440bfaef
commit a601754450

View File

@ -85,31 +85,25 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
{
ReadResult result = ReadResult(ReadResult::FILE_NOT_HANDLED);
if (fin.fail()) return result;
if (!fin.fail())
{
unsigned int ulzipFileLength;
fin.seekg(0,std::ios_base::end);
ulzipFileLength = fin.tellg();
unsigned int ulzipFileLength = fin.tellg();
fin.seekg(0,std::ios_base::beg);
// Decompress stream to standard stream
HZIP hz;
// Need to decouple stream content as I can't see any other way to get access to a byte array
// containing the content in the stream. One saving grace here is that we know that the
// stream has already been fully read in, hence no need to concern ourselves with asynchronous
// reads.
//void * pMemBuffer = malloc(ulzipFileLength);
char * pMemBuffer = new char [ulzipFileLength];
if (pMemBuffer)
{
if (!pMemBuffer) return result;
fin.read(pMemBuffer, ulzipFileLength);
if ((unsigned int)fin.gcount() == ulzipFileLength)
{
hz = OpenZip(pMemBuffer, ulzipFileLength, ""); SetUnzipBaseDir(hz,_T("\\"));
HZIP hz = OpenZip(pMemBuffer, ulzipFileLength, "");
if (hz)
{
ZIPENTRY ze;
GetZipItem(hz,-1,&ze);
int numitems=ze.index;
@ -145,30 +139,24 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
local_opt->setPluginStringData("STREAM_FILENAME",osgDB::getSimpleFileName(StreamName));
result = rw->readNode(buffer,local_opt.get());
if (result.validNode())
ReadResult readResult = rw->readNode(buffer,local_opt.get());
if (readResult.validNode())
{
grp->addChild( result.takeNode() );
grp->addChild(readResult.takeNode());
}
}
}
}
if( grp->getNumChildren() == 0 )
result = ReadResult(ReadResult::FILE_NOT_HANDLED);
else
if (grp->getNumChildren() > 0)
{
result = grp.get();
}
else
result = ReadResult(ReadResult::FILE_NOT_HANDLED);
}
else
result = ReadResult(ReadResult::FILE_NOT_HANDLED);
CloseZip(hz);
}
}
delete [] pMemBuffer;
}
else
result = ReadResult(ReadResult::FILE_NOT_HANDLED);
}
return result;
}